Wiring up new Organisation entity type

This commit is contained in:
Naomi 2020-11-12 17:35:34 +00:00
parent 675a85dfb6
commit 7a9b95bf0d
7 changed files with 331 additions and 5 deletions

View File

@ -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.'))

View File

@ -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"
* }
* )
*/

View File

@ -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'

View File

@ -0,0 +1,55 @@
<?php
namespace Drupal\opencase\Plugin\Derivative;
use Drupal\Component\Plugin\Derivative\DeriverBase;
use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
 * Derivative class that provides the menu links adding various types of organisations
 */
class AddOrganisationsMenuLink extends DeriverBase implements ContainerDeriverInterface {
/**
   * @var EntityTypeManagerInterface $entityTypeManager.
   */
protected $entityTypeManager;
/**
   * Creates a AddOrganisationsMenuLink instance.
   *
   * @param $base_plugin_id
   * @param EntityTypeManagerInterface $entity_type_manager
   */
public function __construct($base_plugin_id, EntityTypeManagerInterface $entity_type_manager) {
$this->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;
}
}

View File

@ -0,0 +1,55 @@
<?php
namespace Drupal\opencase\Plugin\Derivative;
use Drupal\Component\Plugin\Derivative\DeriverBase;
use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
 * Derivative class that provides the menu links adding various types of organisations
 */
class SeeAllOrganisationsMenuLink extends DeriverBase implements ContainerDeriverInterface {
/**
   * @var EntityTypeManagerInterface $entityTypeManager.
   */
protected $entityTypeManager;
/**
   * Creates a SeeAllOrganisationsMenuLink instance.
   *
   * @param $base_plugin_id
   * @param EntityTypeManagerInterface $entity_type_manager
   */
public function __construct($base_plugin_id, EntityTypeManagerInterface $entity_type_manager) {
$this->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;
}
}

View File

@ -0,0 +1,6 @@
<?php
namespace Drupal\opencase\Plugin\Menu;
use Drupal\Core\Menu\MenuLinkDefault;
class AddOrganisationsMenuLink extends MenuLinkDefault {}

View File

@ -0,0 +1,6 @@
<?php
namespace Drupal\opencase\Plugin\Menu;
use Drupal\Core\Menu\MenuLinkDefault;
class SeeAllOrganisationgMenuLink extends MenuLinkDefault {}