From a48e37ad396d82de69267eb3f91dda8ccbfb70c1 Mon Sep 17 00:00:00 2001 From: naomi Date: Wed, 11 Apr 2018 12:18:27 +0200 Subject: [PATCH] Changed name of Profile entity to Hat so as not to conflict with Profile or Profile2 module on existing sites --- .../config/schema/hat_type.schema.yml | 12 + modules/zencrm_entities/hat.page.inc | 30 +++ .../src/Entity/ContactDetails.php | 2 +- modules/zencrm_entities/src/Entity/Hat.php | 210 ++++++++++++++++++ .../src/Entity/HatInterface.php | 77 +++++++ .../zencrm_entities/src/Entity/HatType.php | 58 +++++ .../src/Entity/HatTypeInterface.php | 13 ++ .../src/Entity/HatViewsData.php | 24 ++ .../src/Form/HatDeleteForm.php | 15 ++ modules/zencrm_entities/src/Form/HatForm.php | 50 +++++ .../src/Form/HatSettingsForm.php | 53 +++++ .../src/Form/HatTypeDeleteForm.php | 53 +++++ .../zencrm_entities/src/Form/HatTypeForm.php | 65 ++++++ .../src/HatAccessControlHandler.php | 47 ++++ .../src/HatHtmlRouteProvider.php | 56 +++++ .../zencrm_entities/src/HatListBuilder.php | 40 ++++ .../src/HatTranslationHandler.php | 14 ++ .../src/HatTypeHtmlRouteProvider.php | 28 +++ .../src/HatTypeListBuilder.php | 32 +++ .../templates/hat-content-add-list.html.twig | 23 ++ .../zencrm_entities/templates/hat.html.twig | 22 ++ .../zencrm_entities.links.action.yml | 21 +- .../zencrm_entities.links.menu.yml | 36 +-- .../zencrm_entities.links.task.yml | 41 ++-- .../zencrm_entities/zencrm_entities.module | 28 +-- .../zencrm_entities.permissions.yml | 50 ++--- ...rofileController.php => HatController.php} | 10 +- .../{ProfileCreator.php => HatCreator.php} | 22 +- zencrm.routing.yml | 8 +- 29 files changed, 1024 insertions(+), 116 deletions(-) create mode 100644 modules/zencrm_entities/config/schema/hat_type.schema.yml create mode 100644 modules/zencrm_entities/hat.page.inc create mode 100644 modules/zencrm_entities/src/Entity/Hat.php create mode 100644 modules/zencrm_entities/src/Entity/HatInterface.php create mode 100644 modules/zencrm_entities/src/Entity/HatType.php create mode 100644 modules/zencrm_entities/src/Entity/HatTypeInterface.php create mode 100644 modules/zencrm_entities/src/Entity/HatViewsData.php create mode 100644 modules/zencrm_entities/src/Form/HatDeleteForm.php create mode 100644 modules/zencrm_entities/src/Form/HatForm.php create mode 100644 modules/zencrm_entities/src/Form/HatSettingsForm.php create mode 100644 modules/zencrm_entities/src/Form/HatTypeDeleteForm.php create mode 100644 modules/zencrm_entities/src/Form/HatTypeForm.php create mode 100644 modules/zencrm_entities/src/HatAccessControlHandler.php create mode 100644 modules/zencrm_entities/src/HatHtmlRouteProvider.php create mode 100644 modules/zencrm_entities/src/HatListBuilder.php create mode 100644 modules/zencrm_entities/src/HatTranslationHandler.php create mode 100644 modules/zencrm_entities/src/HatTypeHtmlRouteProvider.php create mode 100644 modules/zencrm_entities/src/HatTypeListBuilder.php create mode 100644 modules/zencrm_entities/templates/hat-content-add-list.html.twig create mode 100644 modules/zencrm_entities/templates/hat.html.twig rename src/Controller/{ProfileController.php => HatController.php} (67%) rename src/Plugin/Block/{ProfileCreator.php => HatCreator.php} (50%) diff --git a/modules/zencrm_entities/config/schema/hat_type.schema.yml b/modules/zencrm_entities/config/schema/hat_type.schema.yml new file mode 100644 index 0000000..a35a59d --- /dev/null +++ b/modules/zencrm_entities/config/schema/hat_type.schema.yml @@ -0,0 +1,12 @@ +zencrm_entities.hat_type.*: + type: config_entity + label: 'Hat type config' + mapping: + id: + type: string + label: 'ID' + label: + type: label + label: 'Label' + uuid: + type: string diff --git a/modules/zencrm_entities/hat.page.inc b/modules/zencrm_entities/hat.page.inc new file mode 100644 index 0000000..fc43680 --- /dev/null +++ b/modules/zencrm_entities/hat.page.inc @@ -0,0 +1,30 @@ +setLabel(t('Person')) - ->setDescription(t('The person this profile is of.')) + ->setDescription(t('The person this set of contact details is for.')) ->setSetting('target_type', 'person') ->setRequired(TRUE); diff --git a/modules/zencrm_entities/src/Entity/Hat.php b/modules/zencrm_entities/src/Entity/Hat.php new file mode 100644 index 0000000..8c0243e --- /dev/null +++ b/modules/zencrm_entities/src/Entity/Hat.php @@ -0,0 +1,210 @@ + \Drupal::currentUser()->id(), + ]; + } + + /** + * {@inheritdoc} + */ + public function getName() { + return $this->get('name')->value; + } + + /** + * {@inheritdoc} + */ + public function setName($name) { + $this->set('name', $name); + return $this; + } + + /** + * {@inheritdoc} + */ + public function getCreatedTime() { + return $this->get('created')->value; + } + + /** + * {@inheritdoc} + */ + public function setCreatedTime($timestamp) { + $this->set('created', $timestamp); + return $this; + } + + /** + * {@inheritdoc} + */ + public function getOwner() { + return $this->get('user_id')->entity; + } + + /** + * {@inheritdoc} + */ + public function getOwnerId() { + return $this->get('user_id')->target_id; + } + + /** + * {@inheritdoc} + */ + public function setOwnerId($uid) { + $this->set('user_id', $uid); + return $this; + } + + /** + * {@inheritdoc} + */ + public function setOwner(UserInterface $account) { + $this->set('user_id', $account->id()); + return $this; + } + + /** + * {@inheritdoc} + */ + public function isPublished() { + return (bool) $this->getEntityKey('status'); + } + + /** + * {@inheritdoc} + */ + public function setPublished($published) { + $this->set('status', $published ? TRUE : FALSE); + return $this; + } + + /** + * {@inheritdoc} + */ + public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { + $fields = parent::baseFieldDefinitions($entity_type); + + $fields['user_id'] = BaseFieldDefinition::create('entity_reference') + ->setLabel(t('Authored by')) + ->setDescription(t('The user ID of the author.')) + ->setRevisionable(TRUE) + ->setSetting('target_type', 'user') + ->setSetting('handler', 'default') + ->setTranslatable(TRUE); + # ->setDisplayOptions('form', [ + # 'type' => 'entity_reference_autocomplete', + # 'weight' => 5, + # 'settings' => [ + # 'match_operator' => 'CONTAINS', + # 'size' => '60', + # 'autocomplete_type' => 'tags', + # 'placeholder' => '', + # ], + # ]); + + // This field is always implied from the context, + // so has no form or view display. + $fields['person'] = BaseFieldDefinition::create('entity_reference') + ->setLabel(t('Person')) + ->setDescription(t('The person this hat is of.')) + ->setSetting('target_type', 'person'); + + // This field is computed in a presave hook, and used for entity reference + // options when selecting a person for involvement in a case etc. + $fields['name'] = BaseFieldDefinition::create('string') + ->setLabel(t('Name')) + ->setDescription(t('The name of this hat instance as it appears in entity reference fields.')); + + $fields['status'] = BaseFieldDefinition::create('boolean') + ->setLabel(t('Publishing status')) + ->setDescription(t('A boolean indicating whether the Hat is published.')) + # ->setDisplayOptions('form', [ + # 'type' => 'boolean_checkbox', + # 'weight' => -3, + # ]) + ->setDefaultValue(TRUE); + + + $fields['created'] = BaseFieldDefinition::create('created') + ->setLabel(t('Created')) + ->setDescription(t('The time that the entity was created.')); + + $fields['changed'] = BaseFieldDefinition::create('changed') + ->setLabel(t('Changed')) + ->setDescription(t('The time that the entity was last edited.')); + + return $fields; + } + +} diff --git a/modules/zencrm_entities/src/Entity/HatInterface.php b/modules/zencrm_entities/src/Entity/HatInterface.php new file mode 100644 index 0000000..477a903 --- /dev/null +++ b/modules/zencrm_entities/src/Entity/HatInterface.php @@ -0,0 +1,77 @@ +entity; + + return $form; + } + + /** + * {@inheritdoc} + */ + public function save(array $form, FormStateInterface $form_state) { + $entity = $this->entity; + + $status = parent::save($form, $form_state); + + switch ($status) { + case SAVED_NEW: + drupal_set_message($this->t('Created the %label Hat.', [ + '%label' => $entity->label(), + ])); + break; + + default: + drupal_set_message($this->t('Saved the %label Hat.', [ + '%label' => $entity->label(), + ])); + } + $form_state->setRedirect('entity.hat.canonical', ['hat' => $entity->id()]); + } + +} diff --git a/modules/zencrm_entities/src/Form/HatSettingsForm.php b/modules/zencrm_entities/src/Form/HatSettingsForm.php new file mode 100644 index 0000000..60a800b --- /dev/null +++ b/modules/zencrm_entities/src/Form/HatSettingsForm.php @@ -0,0 +1,53 @@ +t('Are you sure you want to delete %name?', ['%name' => $this->entity->label()]); + } + + /** + * {@inheritdoc} + */ + public function getCancelUrl() { + return new Url('entity.hat_type.collection'); + } + + /** + * {@inheritdoc} + */ + public function getConfirmText() { + return $this->t('Delete'); + } + + /** + * {@inheritdoc} + */ + public function submitForm(array &$form, FormStateInterface $form_state) { + $this->entity->delete(); + + drupal_set_message( + $this->t('content @type: deleted @label.', + [ + '@type' => $this->entity->bundle(), + '@label' => $this->entity->label(), + ] + ) + ); + + $form_state->setRedirectUrl($this->getCancelUrl()); + } + +} diff --git a/modules/zencrm_entities/src/Form/HatTypeForm.php b/modules/zencrm_entities/src/Form/HatTypeForm.php new file mode 100644 index 0000000..9ec51dd --- /dev/null +++ b/modules/zencrm_entities/src/Form/HatTypeForm.php @@ -0,0 +1,65 @@ +entity; + $form['label'] = [ + '#type' => 'textfield', + '#title' => $this->t('Label'), + '#maxlength' => 255, + '#default_value' => $hat_type->label(), + '#description' => $this->t("Label for the Hat type."), + '#required' => TRUE, + ]; + + $form['id'] = [ + '#type' => 'machine_name', + '#default_value' => $hat_type->id(), + '#machine_name' => [ + 'exists' => '\Drupal\zencrm_entities\Entity\HatType::load', + ], + '#disabled' => !$hat_type->isNew(), + ]; + + /* You will need additional form elements for your custom properties. */ + + return $form; + } + + /** + * {@inheritdoc} + */ + public function save(array $form, FormStateInterface $form_state) { + $hat_type = $this->entity; + $status = $hat_type->save(); + + switch ($status) { + case SAVED_NEW: + drupal_set_message($this->t('Created the %label Hat type.', [ + '%label' => $hat_type->label(), + ])); + break; + + default: + drupal_set_message($this->t('Saved the %label Hat type.', [ + '%label' => $hat_type->label(), + ])); + } + $form_state->setRedirectUrl($hat_type->toUrl('collection')); + } + +} diff --git a/modules/zencrm_entities/src/HatAccessControlHandler.php b/modules/zencrm_entities/src/HatAccessControlHandler.php new file mode 100644 index 0000000..08b91f2 --- /dev/null +++ b/modules/zencrm_entities/src/HatAccessControlHandler.php @@ -0,0 +1,47 @@ +isPublished()) { + return AccessResult::allowedIfHasPermission($account, 'view unpublished hat entities'); + } + return AccessResult::allowedIfHasPermission($account, 'view published hat entities'); + + case 'update': + return AccessResult::allowedIfHasPermission($account, 'edit hat entities'); + + case 'delete': + return AccessResult::allowedIfHasPermission($account, 'delete hat entities'); + } + + // Unknown operation, no opinion. + return AccessResult::neutral(); + } + + /** + * {@inheritdoc} + */ + protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) { + return AccessResult::allowedIfHasPermission($account, 'add hat entities'); + } + +} diff --git a/modules/zencrm_entities/src/HatHtmlRouteProvider.php b/modules/zencrm_entities/src/HatHtmlRouteProvider.php new file mode 100644 index 0000000..0cda5ca --- /dev/null +++ b/modules/zencrm_entities/src/HatHtmlRouteProvider.php @@ -0,0 +1,56 @@ +id(); + + if ($settings_form_route = $this->getSettingsFormRoute($entity_type)) { + $collection->add("$entity_type_id.settings", $settings_form_route); + } + + return $collection; + } + + /** + * Gets the settings form route. + * + * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type + * The entity type. + * + * @return \Symfony\Component\Routing\Route|null + * The generated route, if available. + */ + protected function getSettingsFormRoute(EntityTypeInterface $entity_type) { + if (!$entity_type->getBundleEntityType()) { + $route = new Route("/admin/structure/{$entity_type->id()}/settings"); + $route + ->setDefaults([ + '_form' => 'Drupal\zencrm_entities\Form\HatSettingsForm', + '_title' => "{$entity_type->getLabel()} settings", + ]) + ->setRequirement('_permission', $entity_type->getAdminPermission()) + ->setOption('_admin_route', TRUE); + + return $route; + } + } + +} diff --git a/modules/zencrm_entities/src/HatListBuilder.php b/modules/zencrm_entities/src/HatListBuilder.php new file mode 100644 index 0000000..68af059 --- /dev/null +++ b/modules/zencrm_entities/src/HatListBuilder.php @@ -0,0 +1,40 @@ +t('Hat ID'); + $header['name'] = $this->t('Name'); + return $header + parent::buildHeader(); + } + + /** + * {@inheritdoc} + */ + public function buildRow(EntityInterface $entity) { + /* @var $entity \Drupal\zencrm_entities\Entity\Hat */ + $row['id'] = $entity->id(); + $row['name'] = Link::createFromRoute( + $entity->label(), + 'entity.hat.edit_form', + ['hat' => $entity->id()] + ); + return $row + parent::buildRow($entity); + } + +} diff --git a/modules/zencrm_entities/src/HatTranslationHandler.php b/modules/zencrm_entities/src/HatTranslationHandler.php new file mode 100644 index 0000000..63267a2 --- /dev/null +++ b/modules/zencrm_entities/src/HatTranslationHandler.php @@ -0,0 +1,14 @@ +t('Hat type'); + $header['id'] = $this->t('Machine name'); + return $header + parent::buildHeader(); + } + + /** + * {@inheritdoc} + */ + public function buildRow(EntityInterface $entity) { + $row['label'] = $entity->label(); + $row['id'] = $entity->id(); + // You probably want a few more properties here... + return $row + parent::buildRow($entity); + } + +} diff --git a/modules/zencrm_entities/templates/hat-content-add-list.html.twig b/modules/zencrm_entities/templates/hat-content-add-list.html.twig new file mode 100644 index 0000000..1ae94e5 --- /dev/null +++ b/modules/zencrm_entities/templates/hat-content-add-list.html.twig @@ -0,0 +1,23 @@ +{# +/** + * @file + * Default theme implementation to present a list of custom content entity types/bundles. + * + * Available variables: + * - types: A collection of all the available custom entity types/bundles. + * Each type/bundle contains the following: + * - link: A link to add a content entity of this type. + * - description: A description of this content entity types/bundle. + * + * @see template_preprocess_hat_content_add_list() + * + * @ingroup themeable + */ +#} +{% spaceless %} +
+ {% for type in types %} +
{{ type.link }}
+ {% endfor %} +
+{% endspaceless %} diff --git a/modules/zencrm_entities/templates/hat.html.twig b/modules/zencrm_entities/templates/hat.html.twig new file mode 100644 index 0000000..827d6b5 --- /dev/null +++ b/modules/zencrm_entities/templates/hat.html.twig @@ -0,0 +1,22 @@ +{# +/** + * @file hat.html.twig + * Default theme implementation to present Hat data. + * + * This template is used when viewing Hat pages. + * + * + * Available variables: + * - content: A list of content items. Use 'content' to print all content, or + * - attributes: HTML attributes for the container element. + * + * @see template_preprocess_hat() + * + * @ingroup themeable + */ +#} + + {% if content %} + {{- content -}} + {% endif %} + diff --git a/modules/zencrm_entities/zencrm_entities.links.action.yml b/modules/zencrm_entities/zencrm_entities.links.action.yml index d0a9b65..4c53da0 100644 --- a/modules/zencrm_entities/zencrm_entities.links.action.yml +++ b/modules/zencrm_entities/zencrm_entities.links.action.yml @@ -3,16 +3,6 @@ entity.person.add_form: title: 'Add Person' appears_on: - entity.person.collection -entity.profile.add_form: - route_name: entity.profile.add_page - title: 'Add Profile' - appears_on: - - entity.profile.collection -entity.profile_type.add_form: - route_name: entity.profile_type.add_form - title: 'Add Profile type' - appears_on: - - entity.profile_type.collection entity.contact_details.add_form: route_name: entity.contact_details.add_form @@ -29,3 +19,14 @@ entity.contact_details.add_form: title: 'Add Contact details' appears_on: - entity.contact_details.collection +entity.hat.add_form: + route_name: entity.hat.add_page + title: 'Add Hat' + appears_on: + - entity.hat.collection +entity.hat_type.add_form: + route_name: entity.hat_type.add_form + title: 'Add Hat type' + appears_on: + - entity.hat_type.collection + diff --git a/modules/zencrm_entities/zencrm_entities.links.menu.yml b/modules/zencrm_entities/zencrm_entities.links.menu.yml index 3da7254..fbbedb5 100644 --- a/modules/zencrm_entities/zencrm_entities.links.menu.yml +++ b/modules/zencrm_entities/zencrm_entities.links.menu.yml @@ -13,24 +13,6 @@ person.admin.structure.settings: route_name: person.settings parent: system.admin_structure -# Profile menu items definition -entity.profile.collection: - title: 'Profile list' - route_name: entity.profile.collection - description: 'List Profile entities' - parent: system.admin_structure - weight: 100 - - -# Profile type menu items definition -entity.profile_type.collection: - title: 'Profile type' - route_name: entity.profile_type.collection - description: 'List Profile type (bundles)' - parent: system.admin_structure - weight: 99 - - # Contact Details menu items definition entity.contact_details.collection: title: 'Contact Details list' @@ -72,3 +54,21 @@ contact_details.admin.structure.settings: description: 'Configure Contact details entities' route_name: contact_details.settings parent: system.admin_structure + +# Hat menu items definition +entity.hat.collection: + title: 'Hat list' + route_name: entity.hat.collection + description: 'List Hat entities' + parent: system.admin_structure + weight: 100 + + +# Hat type menu items definition +entity.hat_type.collection: + title: 'Hat type' + route_name: entity.hat_type.collection + description: 'List Hat type (bundles)' + parent: system.admin_structure + weight: 99 + diff --git a/modules/zencrm_entities/zencrm_entities.links.task.yml b/modules/zencrm_entities/zencrm_entities.links.task.yml index 37a3aab..012bc0e 100644 --- a/modules/zencrm_entities/zencrm_entities.links.task.yml +++ b/modules/zencrm_entities/zencrm_entities.links.task.yml @@ -25,29 +25,6 @@ entity.person.delete_form: title: Delete weight: 10 -# Profile routing definition - -entity.profile.canonical: - route_name: entity.profile.canonical - base_route: entity.profile.canonical - title: 'View' - -entity.profile.edit_form: - route_name: entity.profile.edit_form - base_route: entity.profile.canonical - title: 'Edit' - -entity.profile.version_history: - route_name: entity.profile.version_history - base_route: entity.profile.canonical - title: 'Revisions' - -entity.profile.delete_form: - route_name: entity.profile.delete_form - base_route: entity.profile.canonical - title: Delete - weight: 10 - # Contact Details routing definition contact_details.settings_tab: route_name: contact_details.settings @@ -119,3 +96,21 @@ entity.contact_details.delete_form: title: Delete weight: 10 +# Hat routing definition + +entity.hat.canonical: + route_name: entity.hat.canonical + base_route: entity.hat.canonical + title: 'View' + +entity.hat.edit_form: + route_name: entity.hat.edit_form + base_route: entity.hat.canonical + title: 'Edit' + +entity.hat.delete_form: + route_name: entity.hat.delete_form + base_route: entity.hat.canonical + title: Delete + weight: 10 + diff --git a/modules/zencrm_entities/zencrm_entities.module b/modules/zencrm_entities/zencrm_entities.module index c847905..7a77cf4 100644 --- a/modules/zencrm_entities/zencrm_entities.module +++ b/modules/zencrm_entities/zencrm_entities.module @@ -29,9 +29,9 @@ function zencrm_entities_person_presave($entity) { /** * Implements hook_ENTITY_TYPE_presave(). * Computes the name field from the full name of the referenced person - * plus the profile type. + * plus the hat type. */ -function zencrm_entities_profile_presave($entity) { +function zencrm_entities_hat_presave($entity) { $person_id = $entity->person->first()->getValue()['target_id']; $person = \Drupal\zencrm_entities\Entity\Person::load($person_id); $full_name = $person->full_name->getString(); @@ -64,15 +64,15 @@ function zencrm_entities_theme() { $theme['zencrm_entities'] = [ 'render element' => 'children', ]; - $theme['profile'] = [ + $theme['hat'] = [ 'render element' => 'elements', - 'file' => 'profile.page.inc', - 'template' => 'profile', + 'file' => 'hat.page.inc', + 'template' => 'hat', ]; - $theme['profile_content_add_list'] = [ + $theme['hat_content_add_list'] = [ 'render element' => 'content', 'variables' => ['content' => NULL], - 'file' => 'profile.page.inc', + 'file' => 'hat.page.inc', ]; return $theme; } @@ -80,15 +80,15 @@ function zencrm_entities_theme() { /** * Implements hook_theme_suggestions_HOOK(). */ -function zencrm_entities_theme_suggestions_profile(array $variables) { +function zencrm_entities_theme_suggestions_hat(array $variables) { $suggestions = []; - $entity = $variables['elements']['#profile']; + $entity = $variables['elements']['#hat']; $sanitized_view_mode = strtr($variables['elements']['#view_mode'], '.', '_'); - $suggestions[] = 'profile__' . $sanitized_view_mode; - $suggestions[] = 'profile__' . $entity->bundle(); - $suggestions[] = 'profile__' . $entity->bundle() . '__' . $sanitized_view_mode; - $suggestions[] = 'profile__' . $entity->id(); - $suggestions[] = 'profile__' . $entity->id() . '__' . $sanitized_view_mode; + $suggestions[] = 'hat__' . $sanitized_view_mode; + $suggestions[] = 'hat__' . $entity->bundle(); + $suggestions[] = 'hat__' . $entity->bundle() . '__' . $sanitized_view_mode; + $suggestions[] = 'hat__' . $entity->id(); + $suggestions[] = 'hat__' . $entity->id() . '__' . $sanitized_view_mode; return $suggestions; } diff --git a/modules/zencrm_entities/zencrm_entities.permissions.yml b/modules/zencrm_entities/zencrm_entities.permissions.yml index 7c26a82..486c58d 100644 --- a/modules/zencrm_entities/zencrm_entities.permissions.yml +++ b/modules/zencrm_entities/zencrm_entities.permissions.yml @@ -28,36 +28,6 @@ revert all person revisions: delete all person revisions: title: 'Delete all revisions' description: 'Role requires permission to view Person revisions and delete rights for person entities in question or administer person entities.' -add profile entities: - title: 'Create new Profile entities' - -administer profile entities: - title: 'Administer Profile entities' - description: 'Allow to access the administration form to configure Profile entities.' - restrict access: true - -delete profile entities: - title: 'Delete Profile entities' - -edit profile entities: - title: 'Edit Profile entities' - -view published profile entities: - title: 'View published Profile entities' - -view unpublished profile entities: - title: 'View unpublished Profile entities' - -view all profile revisions: - title: 'View all Profile revisions' - -revert all profile revisions: - title: 'Revert all Profile revisions' - description: 'Role requires permission view Profile revisions and edit rights for profile entities in question or administer profile entities.' - -delete all profile revisions: - title: 'Delete all revisions' - description: 'Role requires permission to view Profile revisions and delete rights for profile entities in question or administer profile entities.' add contact details entities: title: 'Create new Contact Details entities' @@ -126,3 +96,23 @@ view published contact details entities: view unpublished contact details entities: title: 'View unpublished Contact details entities' + +add hat entities: + title: 'Create new Hat entities' + +administer hat entities: + title: 'Administer Hat entities' + description: 'Allow to access the administration form to configure Hat entities.' + restrict access: true + +delete hat entities: + title: 'Delete Hat entities' + +edit hat entities: + title: 'Edit Hat entities' + +view published hat entities: + title: 'View published Hat entities' + +view unpublished hat entities: + title: 'View unpublished Hat entities' diff --git a/src/Controller/ProfileController.php b/src/Controller/HatController.php similarity index 67% rename from src/Controller/ProfileController.php rename to src/Controller/HatController.php index 82661e4..26d4b1b 100644 --- a/src/Controller/ProfileController.php +++ b/src/Controller/HatController.php @@ -5,9 +5,9 @@ namespace Drupal\zencrm\Controller; use Drupal\Core\Controller\ControllerBase; /** - * Class ProfileController. + * Class HatController. */ -class ProfileController extends ControllerBase { +class HatController extends ControllerBase { /** * Hello. @@ -15,18 +15,18 @@ class ProfileController extends ControllerBase { * @return string * Return Hello string. */ - public function createProfileForPerson($type, $person_id) { + public function createHatForPerson($type, $person_id) { $values = array( 'type' => $type, 'person' => $person_id ); $node = \Drupal::entityTypeManager() - ->getStorage('profile') + ->getStorage('hat') ->create($values); $form = \Drupal::entityTypeManager() - ->getFormObject('profile', 'default') + ->getFormObject('hat', 'default') ->setEntity($node); return \Drupal::formBuilder()->getForm($form); } diff --git a/src/Plugin/Block/ProfileCreator.php b/src/Plugin/Block/HatCreator.php similarity index 50% rename from src/Plugin/Block/ProfileCreator.php rename to src/Plugin/Block/HatCreator.php index b6d11ef..79747d9 100644 --- a/src/Plugin/Block/ProfileCreator.php +++ b/src/Plugin/Block/HatCreator.php @@ -5,14 +5,14 @@ namespace Drupal\zencrm\Plugin\Block; use Drupal\Core\Block\BlockBase; /** - * Provides a 'ProfileCreator' block. + * Provides a 'HatCreator' block. * * @Block( - * id = "profile_creator", - * admin_label = @Translation("Profile creator"), + * id = "hat_creator", + * admin_label = @Translation("Hat creator"), * ) */ -class ProfileCreator extends BlockBase { +class HatCreator extends BlockBase { /** * {@inheritdoc} @@ -21,15 +21,15 @@ class ProfileCreator extends BlockBase { $person_id = \Drupal::routeMatch()->getParameter('person')->id(); $markup = ""; - // Only offer profile creation on profiles they don't already have. - $profile_types = \Drupal::service('entity_type.bundle.info')->getBundleInfo('profile'); - foreach($profile_types as $id => $type) { - $profiles = \Drupal::entityTypeManager() - ->getStorage('profile') + // Only offer hat creation on hats they don't already have. + $hat_types = \Drupal::service('entity_type.bundle.info')->getBundleInfo('hat'); + foreach($hat_types as $id => $type) { + $hats = \Drupal::entityTypeManager() + ->getStorage('hat') ->loadByProperties(['type' => $id, 'person' => $person_id]); - if (!reset($profiles)) { + if (!reset($hats)) { $label = $type['label']; - $markup .= "

Create $label Profile

"; + $markup .= "

Create $label Hat

"; } } return [ diff --git a/zencrm.routing.yml b/zencrm.routing.yml index 256f6be..3cfef4d 100644 --- a/zencrm.routing.yml +++ b/zencrm.routing.yml @@ -1,7 +1,7 @@ -zencrm.profile.create: - path: '/zencrm/profile/add/{type}/{person_id}' +zencrm.hat.create: + path: '/zencrm/hat/add/{type}/{person_id}' defaults: - _controller: '\Drupal\zencrm\Controller\ProfileController::createProfileForPerson' - _title: 'Add New Profile' + _controller: '\Drupal\zencrm\Controller\HatController::createHatForPerson' + _title: 'Add New Hat' requirements: _permission: 'access content'