From 7a9b95bf0d64913f3e1d50b0ebf1e33dee212d27 Mon Sep 17 00:00:00 2001 From: Naomi Date: Thu, 12 Nov 2020 17:35:34 +0000 Subject: [PATCH] Wiring up new Organisation entity type --- .../src/Entity/OCOrganisation.php | 197 ++++++++++++++++++ .../src/Entity/OCOrganisationType.php | 10 +- opencase.links.menu.yml | 7 + .../Derivative/AddOrganisationssMenuLink.php | 55 +++++ .../SeeAllOrganisationsMenuLink.php | 55 +++++ src/Plugin/Menu/AddOrganisationssMenuLink.php | 6 + .../Menu/SeeAllOrganisationsMenuLink.php | 6 + 7 files changed, 331 insertions(+), 5 deletions(-) create mode 100644 src/Plugin/Derivative/AddOrganisationssMenuLink.php create mode 100644 src/Plugin/Derivative/SeeAllOrganisationsMenuLink.php create mode 100644 src/Plugin/Menu/AddOrganisationssMenuLink.php create mode 100644 src/Plugin/Menu/SeeAllOrganisationsMenuLink.php diff --git a/modules/opencase_entities/src/Entity/OCOrganisation.php b/modules/opencase_entities/src/Entity/OCOrganisation.php index 6cc6d25..27f30d0 100644 --- a/modules/opencase_entities/src/Entity/OCOrganisation.php +++ b/modules/opencase_entities/src/Entity/OCOrganisation.php @@ -194,6 +194,203 @@ class OCOrganisation extends EditorialContentEntityBase implements OCOrganisatio // Add the published field. $fields += static::publishedBaseFieldDefinitions($entity_type); + $fields['notes'] = BaseFieldDefinition::create('string_long') + ->setRevisionable(TRUE) + ->setLabel(t('Notes')) + ->setSettings(array( + 'default_value' => '', + 'max_length' => 255, + 'text_processing' => 0, + )) + ->setDisplayOptions('view', array( + 'label' => 'above', + 'type' => 'basic_string', + 'weight' => -10, + )) + ->setDisplayOptions('form', array( + 'type' => 'string_textarea', + 'weight' => -10, + )); + $fields['contact_name'] = BaseFieldDefinition::create('string') + ->setLabel(t('Contact Name')) + ->setDescription(t('Name of the main contact for this client.')) + ->setRevisionable(TRUE) + ->setSettings([ + 'max_length' => 50, + 'text_processing' => 0, + ]) + ->setDefaultValue('') + ->setDisplayOptions('view', [ + 'label' => 'above', + 'type' => 'string', + 'weight' => -8, + ]) + ->setDisplayOptions('form', [ + 'type' => 'string_textfield', + 'weight' => -8, + ]) + ->setRequired(FALSE); + + $fields['email'] = BaseFieldDefinition::create('string') + ->setLabel(t('Email Address')) + ->setRevisionable(TRUE) + ->setSettings(array( + 'default_value' => '', + 'max_length' => 30, + 'text_processing' => 0, + )) + ->setDisplayOptions('view', array( + 'label' => 'above', + 'type' => 'string', + 'weight' => -8, + )) + ->setDisplayOptions('form', array( + 'type' => 'string_textfield', + 'weight' => -8, + )); + + $fields['phone'] = BaseFieldDefinition::create('string') + ->setLabel(t('Phone Number')) + ->setRevisionable(TRUE) + ->setSettings(array( + 'default_value' => '', + 'max_length' => 20, + 'text_processing' => 0, + )) + ->setDisplayOptions('view', array( + 'label' => 'above', + 'type' => 'string', + 'weight' => -7, + )) + ->setDisplayOptions('form', array( + 'type' => 'string_textfield', + 'weight' => -7, + )); + $fields['postal_address'] = BaseFieldDefinition::create('string_long') + ->setRevisionable(TRUE) + ->setLabel(t('Postal Address')) + ->setDescription(t('Full address, apart from post code.')) + ->setSettings(array( + 'default_value' => '', + 'max_length' => 255, + 'text_processing' => 0, + )) + ->setDisplayOptions('view', array( + 'label' => 'above', + 'type' => 'basic_string', + 'weight' => -5, + )) + ->setDisplayOptions('form', array( + 'type' => 'string_textarea', + 'weight' => -5, + )); + $fields['post_code'] = BaseFieldDefinition::create('string') + ->setRevisionable(TRUE) + ->setLabel(t('Post Code')) + ->setSettings(array( + 'default_value' => '', + 'max_length' => 10, + 'text_processing' => 0, + )) + ->setDisplayOptions('view', array( + 'label' => 'above', + 'type' => 'string', + 'weight' => -4, + )) + ->setDisplayOptions('form', array( + 'type' => 'string_textfield', + 'weight' => -4, + )); + $fields['billing_contact_name'] = BaseFieldDefinition::create('string') + ->setLabel(t('Billing Contact Name')) + ->setDescription(t('Name of the main contact for this client.')) + ->setRevisionable(TRUE) + ->setSettings([ + 'max_length' => 50, + 'text_processing' => 0, + ]) + ->setDefaultValue('') + ->setDisplayOptions('view', [ + 'label' => 'above', + 'type' => 'string', + 'weight' => -3, + ]) + ->setDisplayOptions('form', [ + 'type' => 'string_textfield', + 'weight' => -3, + ]) + ->setRequired(FALSE); + + $fields['billing_email'] = BaseFieldDefinition::create('string') + ->setLabel(t('Billing Email Address')) + ->setRevisionable(TRUE) + ->setSettings(array( + 'default_value' => '', + 'max_length' => 30, + 'text_processing' => 0, + )) + ->setDisplayOptions('view', array( + 'label' => 'above', + 'type' => 'string', + 'weight' => -2, + )) + ->setDisplayOptions('form', array( + 'type' => 'string_textfield', + 'weight' => -2, + )); + + $fields['billing_phone'] = BaseFieldDefinition::create('string') + ->setLabel(t('Billing Phone Number')) + ->setRevisionable(TRUE) + ->setSettings(array( + 'default_value' => '', + 'max_length' => 20, + 'text_processing' => 0, + )) + ->setDisplayOptions('view', array( + 'label' => 'above', + 'type' => 'string', + 'weight' => -1, + )) + ->setDisplayOptions('form', array( + 'type' => 'string_textfield', + 'weight' => -1, + )); + $fields['billing_postal_address'] = BaseFieldDefinition::create('string_long') + ->setRevisionable(TRUE) + ->setLabel(t('Billing Postal Address')) + ->setDescription(t('Full address, apart from post code.')) + ->setSettings(array( + 'default_value' => '', + 'max_length' => 255, + 'text_processing' => 0, + )) + ->setDisplayOptions('view', array( + 'label' => 'above', + 'type' => 'basic_string', + 'weight' => -0, + )) + ->setDisplayOptions('form', array( + 'type' => 'string_textarea', + 'weight' => -0, + )); + $fields['billing_post_code'] = BaseFieldDefinition::create('string') + ->setRevisionable(TRUE) + ->setLabel(t('Billing Post Code')) + ->setSettings(array( + 'default_value' => '', + 'max_length' => 10, + 'text_processing' => 0, + )) + ->setDisplayOptions('view', array( + 'label' => 'above', + 'type' => 'string', + 'weight' => 1, + )) + ->setDisplayOptions('form', array( + 'type' => 'string_textfield', + 'weight' => 1, + )); $fields['user_id'] = BaseFieldDefinition::create('entity_reference') ->setLabel(t('Authored by')) ->setDescription(t('The user ID of author of the Organisation entity.')) diff --git a/modules/opencase_entities/src/Entity/OCOrganisationType.php b/modules/opencase_entities/src/Entity/OCOrganisationType.php index 162b422..6e77063 100644 --- a/modules/opencase_entities/src/Entity/OCOrganisationType.php +++ b/modules/opencase_entities/src/Entity/OCOrganisationType.php @@ -31,11 +31,11 @@ use Drupal\Core\Config\Entity\ConfigEntityBundleBase; * "uuid" = "uuid" * }, * links = { - * "canonical" = "/opencase/oc_organisation_type/{oc_organisation_type}", - * "add-form" = "/opencase/oc_organisation_type/add", - * "edit-form" = "/opencase/oc_organisation_type/{oc_organisation_type}/edit", - * "delete-form" = "/opencase/oc_organisation_type/{oc_organisation_type}/delete", - * "collection" = "/opencase/oc_organisation_type" + * "canonical" = "/admin/opencase/oc_organisation_type/{oc_organisation_type}", + * "add-form" = "/admin/opencase/oc_organisation_type/add", + * "edit-form" = "/admin/opencase/oc_organisation_type/{oc_organisation_type}/edit", + * "delete-form" = "/admin/opencase/oc_organisation_type/{oc_organisation_type}/delete", + * "collection" = "/admin/opencase/oc_organisation_type" * } * ) */ diff --git a/opencase.links.menu.yml b/opencase.links.menu.yml index fc464d5..3cdaa02 100644 --- a/opencase.links.menu.yml +++ b/opencase.links.menu.yml @@ -31,6 +31,13 @@ opencase.manage_user_logins: parent: opencase.opencase_admin_menu url: internal:/admin/people weight: 0 +opencase.manage_organisation_types: + title: 'Manage organisation types' + description: 'Configure types of people and their fields' + menu_name: opencase + parent: opencase.opencase_admin_menu + url: internal:/admin/opencase/oc_organisation_type + weight: 1 opencase.manage_person_types: title: 'Manage person types' description: 'Configure types of people and their fields' diff --git a/src/Plugin/Derivative/AddOrganisationssMenuLink.php b/src/Plugin/Derivative/AddOrganisationssMenuLink.php new file mode 100644 index 0000000..1ebf82a --- /dev/null +++ b/src/Plugin/Derivative/AddOrganisationssMenuLink.php @@ -0,0 +1,55 @@ +entityTypeManager = $entity_type_manager; + } + + /** +   * {@inheritdoc} +   */ + public static function create(ContainerInterface $container, $base_plugin_id) { + return new static( + $base_plugin_id, + $container->get('entity_type.manager') + ); + } + /** +   * {@inheritdoc} +   */ + public function getDerivativeDefinitions($base_plugin_definition) { + $links = []; + $organisationTypes = $this->entityTypeManager->getStorage('oc_organisation_type')->loadMultiple(); + foreach ($organisationTypes as $id => $organisationType) { + $links[$id] = [ + 'title' => "Add ". $organisationType->label(), + 'route_name' => "entity.oc_organisation.add_form", + 'route_parameters' => ['oc_organisation_type' => $organisationType->id()] + ] + $base_plugin_definition; + } + return $links; + } +} diff --git a/src/Plugin/Derivative/SeeAllOrganisationsMenuLink.php b/src/Plugin/Derivative/SeeAllOrganisationsMenuLink.php new file mode 100644 index 0000000..0664f4f --- /dev/null +++ b/src/Plugin/Derivative/SeeAllOrganisationsMenuLink.php @@ -0,0 +1,55 @@ +entityTypeManager = $entity_type_manager; + } + + /** +   * {@inheritdoc} +   */ + public static function create(ContainerInterface $container, $base_plugin_id) { + return new static( + $base_plugin_id, + $container->get('entity_type.manager') + ); + } + /** +   * {@inheritdoc} +   */ + public function getDerivativeDefinitions($base_plugin_definition) { + $links = []; + $organisationTypes = $this->entityTypeManager->getStorage('oc_organisation_type')->loadMultiple(); + foreach ($organisationTypes as $id => $organisationType) { + $links[$id] = [ + 'title' => $organisationType->label().'s', + 'route_name' => "view.all_organisations_of_a_type.page_1", + 'route_parameters' => ['organisation_type' => $organisationType->id()] + ] + $base_plugin_definition; + } + return $links; + } +} diff --git a/src/Plugin/Menu/AddOrganisationssMenuLink.php b/src/Plugin/Menu/AddOrganisationssMenuLink.php new file mode 100644 index 0000000..6ae4f6d --- /dev/null +++ b/src/Plugin/Menu/AddOrganisationssMenuLink.php @@ -0,0 +1,6 @@ +