Wiring up new Organisation entity type
This commit is contained in:
parent
675a85dfb6
commit
7a9b95bf0d
@ -194,6 +194,203 @@ class OCOrganisation extends EditorialContentEntityBase implements OCOrganisatio
|
|||||||
// Add the published field.
|
// Add the published field.
|
||||||
$fields += static::publishedBaseFieldDefinitions($entity_type);
|
$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')
|
$fields['user_id'] = BaseFieldDefinition::create('entity_reference')
|
||||||
->setLabel(t('Authored by'))
|
->setLabel(t('Authored by'))
|
||||||
->setDescription(t('The user ID of author of the Organisation entity.'))
|
->setDescription(t('The user ID of author of the Organisation entity.'))
|
||||||
|
@ -31,11 +31,11 @@ use Drupal\Core\Config\Entity\ConfigEntityBundleBase;
|
|||||||
* "uuid" = "uuid"
|
* "uuid" = "uuid"
|
||||||
* },
|
* },
|
||||||
* links = {
|
* links = {
|
||||||
* "canonical" = "/opencase/oc_organisation_type/{oc_organisation_type}",
|
* "canonical" = "/admin/opencase/oc_organisation_type/{oc_organisation_type}",
|
||||||
* "add-form" = "/opencase/oc_organisation_type/add",
|
* "add-form" = "/admin/opencase/oc_organisation_type/add",
|
||||||
* "edit-form" = "/opencase/oc_organisation_type/{oc_organisation_type}/edit",
|
* "edit-form" = "/admin/opencase/oc_organisation_type/{oc_organisation_type}/edit",
|
||||||
* "delete-form" = "/opencase/oc_organisation_type/{oc_organisation_type}/delete",
|
* "delete-form" = "/admin/opencase/oc_organisation_type/{oc_organisation_type}/delete",
|
||||||
* "collection" = "/opencase/oc_organisation_type"
|
* "collection" = "/admin/opencase/oc_organisation_type"
|
||||||
* }
|
* }
|
||||||
* )
|
* )
|
||||||
*/
|
*/
|
||||||
|
@ -31,6 +31,13 @@ opencase.manage_user_logins:
|
|||||||
parent: opencase.opencase_admin_menu
|
parent: opencase.opencase_admin_menu
|
||||||
url: internal:/admin/people
|
url: internal:/admin/people
|
||||||
weight: 0
|
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:
|
opencase.manage_person_types:
|
||||||
title: 'Manage person types'
|
title: 'Manage person types'
|
||||||
description: 'Configure types of people and their fields'
|
description: 'Configure types of people and their fields'
|
||||||
|
55
src/Plugin/Derivative/AddOrganisationssMenuLink.php
Normal file
55
src/Plugin/Derivative/AddOrganisationssMenuLink.php
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
55
src/Plugin/Derivative/SeeAllOrganisationsMenuLink.php
Normal file
55
src/Plugin/Derivative/SeeAllOrganisationsMenuLink.php
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
6
src/Plugin/Menu/AddOrganisationssMenuLink.php
Normal file
6
src/Plugin/Menu/AddOrganisationssMenuLink.php
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?php
|
||||||
|
namespace Drupal\opencase\Plugin\Menu;
|
||||||
|
|
||||||
|
use Drupal\Core\Menu\MenuLinkDefault;
|
||||||
|
|
||||||
|
class AddOrganisationsMenuLink extends MenuLinkDefault {}
|
6
src/Plugin/Menu/SeeAllOrganisationsMenuLink.php
Normal file
6
src/Plugin/Menu/SeeAllOrganisationsMenuLink.php
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?php
|
||||||
|
namespace Drupal\opencase\Plugin\Menu;
|
||||||
|
|
||||||
|
use Drupal\Core\Menu\MenuLinkDefault;
|
||||||
|
|
||||||
|
class SeeAllOrganisationgMenuLink extends MenuLinkDefault {}
|
Reference in New Issue
Block a user