Added Organisation Relation entity with update hook to install it, bumped version
This commit is contained in:
parent
26d78a4f7f
commit
d151b1744e
@ -0,0 +1,12 @@
|
||||
opencase_entities.oc_organisation_relation_type.*:
|
||||
type: config_entity
|
||||
label: 'Organisation Relation type config'
|
||||
mapping:
|
||||
id:
|
||||
type: string
|
||||
label: 'ID'
|
||||
label:
|
||||
type: label
|
||||
label: 'Label'
|
||||
uuid:
|
||||
type: string
|
30
modules/opencase_entities/oc_organisation_relation.page.inc
Normal file
30
modules/opencase_entities/oc_organisation_relation.page.inc
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains oc_organisation_relation.page.inc.
|
||||
*
|
||||
* Page callback for Organisation Relation entities.
|
||||
*/
|
||||
|
||||
use Drupal\Core\Render\Element;
|
||||
|
||||
/**
|
||||
* Prepares variables for Organisation Relation templates.
|
||||
*
|
||||
* Default template: oc_organisation_relation.html.twig.
|
||||
*
|
||||
* @param array $variables
|
||||
* An associative array containing:
|
||||
* - elements: An associative array containing the user information and any
|
||||
* - attributes: HTML attributes for the containing element.
|
||||
*/
|
||||
function template_preprocess_oc_organisation_relation(array &$variables) {
|
||||
// Fetch OCOrganisationRelation Entity Object.
|
||||
$oc_organisation_relation = $variables['elements']['#oc_organisation_relation'];
|
||||
|
||||
// Helpful $content variable for templates.
|
||||
foreach (Element::children($variables['elements']) as $key) {
|
||||
$variables['content'][$key] = $variables['elements'][$key];
|
||||
}
|
||||
}
|
@ -4,6 +4,12 @@
|
||||
use \Drupal\Core\Entity\Sql\SqlContentEntityStorageSchemaConverter;
|
||||
use \Drupal\Core\Field\BaseFieldDefinition;
|
||||
|
||||
function opencase_entities_update_80202() {
|
||||
\Drupal::entityTypeManager()->clearCachedDefinitions();
|
||||
\Drupal::entityDefinitionUpdateManager()
|
||||
->installEntityType(\Drupal::entityTypeManager()->getDefinition('oc_organisation_relation'));
|
||||
}
|
||||
|
||||
function opencase_entities_update_80201() {
|
||||
$update_manager = \Drupal::entityDefinitionUpdateManager();
|
||||
$definition = $update_manager->getFieldStorageDefinition('phone', 'oc_actor');
|
||||
|
@ -50,3 +50,13 @@ entity.oc_equal_opps.add_form:
|
||||
title: 'Add Equal Opps'
|
||||
appears_on:
|
||||
- entity.oc_equal_opps.collection
|
||||
entity.oc_organisation_relation.add_form:
|
||||
route_name: entity.oc_organisation_relation.add_page
|
||||
title: 'Add Organisation Relation'
|
||||
appears_on:
|
||||
- entity.oc_organisation_relation.collection
|
||||
entity.oc_organisation_relation_type.add_form:
|
||||
route_name: entity.oc_organisation_relation_type.add_form
|
||||
title: 'Add Organisation Relation type'
|
||||
appears_on:
|
||||
- entity.oc_organisation_relation_type.collection
|
||||
|
@ -96,3 +96,20 @@ oc_equal_opps.admin.structure.settings:
|
||||
description: 'Configure Equal Opps entities'
|
||||
route_name: oc_equal_opps.settings
|
||||
parent: system.admin_structure
|
||||
|
||||
# Organisation Relation menu items definition
|
||||
entity.oc_organisation_relation.collection:
|
||||
title: 'Organisation Relation list'
|
||||
route_name: entity.oc_organisation_relation.collection
|
||||
description: 'List Organisation Relation entities'
|
||||
parent: system.admin_structure
|
||||
weight: 100
|
||||
|
||||
|
||||
# Organisation Relation type menu items definition
|
||||
entity.oc_organisation_relation_type.collection:
|
||||
title: 'Organisation Relation type'
|
||||
route_name: entity.oc_organisation_relation_type.collection
|
||||
description: 'List Organisation Relation type (bundles)'
|
||||
parent: system.admin_structure
|
||||
weight: 99
|
||||
|
@ -126,3 +126,20 @@ entity.oc_equal_opps.delete_form:
|
||||
base_route: entity.oc_equal_opps.canonical
|
||||
title: Delete
|
||||
weight: 10
|
||||
# Organisation Relation routing definition
|
||||
|
||||
entity.oc_organisation_relation.canonical:
|
||||
route_name: entity.oc_organisation_relation.canonical
|
||||
base_route: entity.oc_organisation_relation.canonical
|
||||
title: 'View'
|
||||
|
||||
entity.oc_organisation_relation.edit_form:
|
||||
route_name: entity.oc_organisation_relation.edit_form
|
||||
base_route: entity.oc_organisation_relation.canonical
|
||||
title: 'Edit'
|
||||
|
||||
entity.oc_organisation_relation.delete_form:
|
||||
route_name: entity.oc_organisation_relation.delete_form
|
||||
base_route: entity.oc_organisation_relation.canonical
|
||||
title: Delete
|
||||
weight: 10
|
||||
|
@ -29,6 +29,16 @@ function opencase_entities_help($route_name, RouteMatchInterface $route_match) {
|
||||
*/
|
||||
function opencase_entities_theme() {
|
||||
$theme = [];
|
||||
$theme['oc_organisation_relation'] = [
|
||||
'render element' => 'elements',
|
||||
'file' => 'oc_organisation_relation.page.inc',
|
||||
'template' => 'oc_organisation_relation',
|
||||
];
|
||||
$theme['oc_organisation_relation_content_add_list'] = [
|
||||
'render element' => 'content',
|
||||
'variables' => ['content' => NULL],
|
||||
'file' => 'oc_organisation_relation.page.inc',
|
||||
];
|
||||
$theme['opencase_entities'] = [
|
||||
'render element' => 'children',
|
||||
];
|
||||
@ -140,3 +150,19 @@ function opencase_entities_theme_suggestions_oc_event(array $variables) {
|
||||
return $suggestions;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Implements hook_theme_suggestions_HOOK().
|
||||
*/
|
||||
function opencase_entities_theme_suggestions_oc_organisation_relation(array $variables) {
|
||||
$suggestions = [];
|
||||
$entity = $variables['elements']['#oc_organisation_relation'];
|
||||
$sanitized_view_mode = strtr($variables['elements']['#view_mode'], '.', '_');
|
||||
|
||||
$suggestions[] = 'oc_organisation_relation__' . $sanitized_view_mode;
|
||||
$suggestions[] = 'oc_organisation_relation__' . $entity->bundle();
|
||||
$suggestions[] = 'oc_organisation_relation__' . $entity->bundle() . '__' . $sanitized_view_mode;
|
||||
$suggestions[] = 'oc_organisation_relation__' . $entity->id();
|
||||
$suggestions[] = 'oc_organisation_relation__' . $entity->id() . '__' . $sanitized_view_mode;
|
||||
return $suggestions;
|
||||
}
|
||||
|
@ -177,3 +177,23 @@ view published equal opps entities:
|
||||
view unpublished equal opps entities:
|
||||
title: 'View unpublished Equal Opps entities'
|
||||
|
||||
add organisation relation entities:
|
||||
title: 'Create new Organisation Relation entities'
|
||||
|
||||
administer organisation relation entities:
|
||||
title: 'Administer Organisation Relation entities'
|
||||
description: 'Allow to access the administration form to configure Organisation Relation entities.'
|
||||
restrict access: true
|
||||
|
||||
delete organisation relation entities:
|
||||
title: 'Delete Organisation Relation entities'
|
||||
|
||||
edit organisation relation entities:
|
||||
title: 'Edit Organisation Relation entities'
|
||||
|
||||
view published organisation relation entities:
|
||||
title: 'View published Organisation Relation entities'
|
||||
|
||||
view unpublished organisation relation entities:
|
||||
title: 'View unpublished Organisation Relation entities'
|
||||
|
||||
|
156
modules/opencase_entities/src/Entity/OCOrganisationRelation.php
Normal file
156
modules/opencase_entities/src/Entity/OCOrganisationRelation.php
Normal file
@ -0,0 +1,156 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\opencase_entities\Entity;
|
||||
|
||||
use Drupal\Core\Field\BaseFieldDefinition;
|
||||
use Drupal\Core\Entity\ContentEntityBase;
|
||||
use Drupal\Core\Entity\EntityChangedTrait;
|
||||
use Drupal\Core\Entity\EntityPublishedTrait;
|
||||
use Drupal\Core\Entity\EntityTypeInterface;
|
||||
|
||||
/**
|
||||
* Defines the Organisation Relation entity.
|
||||
*
|
||||
* @ingroup opencase_entities
|
||||
*
|
||||
* @ContentEntityType(
|
||||
* id = "oc_organisation_relation",
|
||||
* label = @Translation("Organisation Relation"),
|
||||
* bundle_label = @Translation("Organisation Relation type"),
|
||||
* handlers = {
|
||||
* "view_builder" = "Drupal\Core\Entity\EntityViewBuilder",
|
||||
* "list_builder" = "Drupal\opencase_entities\OCOrganisationRelationListBuilder",
|
||||
* "views_data" = "Drupal\opencase_entities\Entity\OCOrganisationRelationViewsData",
|
||||
*
|
||||
* "form" = {
|
||||
* "default" = "Drupal\opencase_entities\Form\OCOrganisationRelationForm",
|
||||
* "add" = "Drupal\opencase_entities\Form\OCOrganisationRelationForm",
|
||||
* "edit" = "Drupal\opencase_entities\Form\OCOrganisationRelationForm",
|
||||
* "delete" = "Drupal\opencase_entities\Form\OCOrganisationRelationDeleteForm",
|
||||
* },
|
||||
* "route_provider" = {
|
||||
* "html" = "Drupal\opencase_entities\OCOrganisationRelationHtmlRouteProvider",
|
||||
* },
|
||||
* "access" = "Drupal\opencase_entities\OCOrganisationRelationAccessControlHandler",
|
||||
* },
|
||||
* base_table = "oc_organisation_relation",
|
||||
* translatable = FALSE,
|
||||
* admin_permission = "administer organisation relation entities",
|
||||
* entity_keys = {
|
||||
* "id" = "id",
|
||||
* "bundle" = "type",
|
||||
* "label" = "name",
|
||||
* "uuid" = "uuid",
|
||||
* "langcode" = "langcode",
|
||||
* "published" = "status",
|
||||
* },
|
||||
* links = {
|
||||
* "canonical" = "/opencase/oc_organisation_relation/{oc_organisation_relation}",
|
||||
* "add-page" = "/opencase//oc_organisation_relation/add",
|
||||
* "add-form" = "/opencase/oc_organisation_relation/add/{oc_organisation_relation_type}",
|
||||
* "edit-form" = "/opencase/oc_organisation_relation/{oc_organisation_relation}/edit",
|
||||
* "delete-form" = "/opencase/oc_organisation_relation/{oc_organisation_relation}/delete",
|
||||
* "collection" = "/opencase/oc_organisation_relation",
|
||||
* },
|
||||
* bundle_entity_type = "oc_organisation_relation_type",
|
||||
* field_ui_base_route = "entity.oc_organisation_relation_type.edit_form"
|
||||
* )
|
||||
*/
|
||||
class OCOrganisationRelation extends ContentEntityBase implements OCOrganisationRelationInterface {
|
||||
|
||||
use EntityChangedTrait;
|
||||
use EntityPublishedTrait;
|
||||
|
||||
/**
|
||||
* {@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 static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
|
||||
$fields = parent::baseFieldDefinitions($entity_type);
|
||||
|
||||
// Add the published field.
|
||||
$fields += static::publishedBaseFieldDefinitions($entity_type);
|
||||
|
||||
$fields['name'] = BaseFieldDefinition::create('string')
|
||||
->setLabel(t('Name'))
|
||||
->setDescription(t('The name of the Organisation Relation entity.'))
|
||||
->setSettings([
|
||||
'max_length' => 50,
|
||||
'text_processing' => 0,
|
||||
])
|
||||
->setDefaultValue('Link between organisations')
|
||||
->setRequired(TRUE);
|
||||
|
||||
$fields['status']->setDescription(t('A boolean indicating whether the Organisation Relation is published.'))
|
||||
->setDisplayOptions('form', [
|
||||
'type' => 'boolean_checkbox',
|
||||
'weight' => -3,
|
||||
]);
|
||||
|
||||
$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.'));
|
||||
|
||||
$fields['organisations'] = BaseFieldDefinition::create('entity_reference')
|
||||
->setLabel(t('Organisations'))
|
||||
->setDescription(t('Linked organisations'))
|
||||
->setSetting('target_type', 'oc_organisation')
|
||||
->setSetting('handler', 'default')
|
||||
->setCardinality(2)
|
||||
->setDisplayOptions('form', [
|
||||
'label' => 'above',
|
||||
'type' => 'entity_reference_autocomplete',
|
||||
'weight' => -2,
|
||||
'settings' => [
|
||||
'match_operator' => 'CONTAINS',
|
||||
'size' => '60',
|
||||
'autocomplete_type' => 'tags',
|
||||
'placeholder' => '',
|
||||
],
|
||||
])
|
||||
->setDisplayOptions('view', [
|
||||
'label' => 'above',
|
||||
])
|
||||
->setDefaultValueCallback('opencase_entities_organisation_relation_callback')
|
||||
->setRequired(TRUE);
|
||||
return $fields;
|
||||
}
|
||||
}
|
||||
|
||||
function opencase_entities_organisation_relation_callback() {
|
||||
return [\Drupal::request()->query->get('organisation_id')];
|
||||
}
|
||||
|
@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\opencase_entities\Entity;
|
||||
|
||||
use Drupal\Core\Entity\ContentEntityInterface;
|
||||
use Drupal\Core\Entity\EntityChangedInterface;
|
||||
use Drupal\Core\Entity\EntityPublishedInterface;
|
||||
|
||||
/**
|
||||
* Provides an interface for defining Organisation Relation entities.
|
||||
*
|
||||
* @ingroup opencase_entities
|
||||
*/
|
||||
interface OCOrganisationRelationInterface extends ContentEntityInterface, EntityChangedInterface, EntityPublishedInterface {
|
||||
|
||||
/**
|
||||
* Add get/set methods for your configuration properties here.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Gets the Organisation Relation name.
|
||||
*
|
||||
* @return string
|
||||
* Name of the Organisation Relation.
|
||||
*/
|
||||
public function getName();
|
||||
|
||||
/**
|
||||
* Sets the Organisation Relation name.
|
||||
*
|
||||
* @param string $name
|
||||
* The Organisation Relation name.
|
||||
*
|
||||
* @return \Drupal\opencase_entities\Entity\OCOrganisationRelationInterface
|
||||
* The called Organisation Relation entity.
|
||||
*/
|
||||
public function setName($name);
|
||||
|
||||
/**
|
||||
* Gets the Organisation Relation creation timestamp.
|
||||
*
|
||||
* @return int
|
||||
* Creation timestamp of the Organisation Relation.
|
||||
*/
|
||||
public function getCreatedTime();
|
||||
|
||||
/**
|
||||
* Sets the Organisation Relation creation timestamp.
|
||||
*
|
||||
* @param int $timestamp
|
||||
* The Organisation Relation creation timestamp.
|
||||
*
|
||||
* @return \Drupal\opencase_entities\Entity\OCOrganisationRelationInterface
|
||||
* The called Organisation Relation entity.
|
||||
*/
|
||||
public function setCreatedTime($timestamp);
|
||||
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\opencase_entities\Entity;
|
||||
|
||||
use Drupal\Core\Config\Entity\ConfigEntityBundleBase;
|
||||
|
||||
/**
|
||||
* Defines the Organisation Relation type entity.
|
||||
*
|
||||
* @ConfigEntityType(
|
||||
* id = "oc_organisation_relation_type",
|
||||
* label = @Translation("Organisation Relation type"),
|
||||
* handlers = {
|
||||
* "view_builder" = "Drupal\Core\Entity\EntityViewBuilder",
|
||||
* "list_builder" = "Drupal\opencase_entities\OCOrganisationRelationTypeListBuilder",
|
||||
* "form" = {
|
||||
* "add" = "Drupal\opencase_entities\Form\OCOrganisationRelationTypeForm",
|
||||
* "edit" = "Drupal\opencase_entities\Form\OCOrganisationRelationTypeForm",
|
||||
* "delete" = "Drupal\opencase_entities\Form\OCOrganisationRelationTypeDeleteForm"
|
||||
* },
|
||||
* "route_provider" = {
|
||||
* "html" = "Drupal\opencase_entities\OCOrganisationRelationTypeHtmlRouteProvider",
|
||||
* },
|
||||
* },
|
||||
* config_prefix = "oc_organisation_relation_type",
|
||||
* admin_permission = "administer site configuration",
|
||||
* bundle_of = "oc_organisation_relation",
|
||||
* entity_keys = {
|
||||
* "id" = "id",
|
||||
* "label" = "label",
|
||||
* "uuid" = "uuid"
|
||||
* },
|
||||
* links = {
|
||||
* "canonical" = "/admin/opencase/oc_organisation_relation_type/{oc_organisation_relation_type}",
|
||||
* "add-form" = "/admin/opencase/oc_organisation_relation_type/add",
|
||||
* "edit-form" = "/admin/opencase/oc_organisation_relation_type/{oc_organisation_relation_type}/edit",
|
||||
* "delete-form" = "/admin/opencase/oc_organisation_relation_type/{oc_organisation_relation_type}/delete",
|
||||
* "collection" = "/admin/opencase/oc_organisation_relation_type"
|
||||
* }
|
||||
* )
|
||||
*/
|
||||
class OCOrganisationRelationType extends ConfigEntityBundleBase implements OCOrganisationRelationTypeInterface {
|
||||
|
||||
/**
|
||||
* The Organisation Relation type ID.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $id;
|
||||
|
||||
/**
|
||||
* The Organisation Relation type label.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $label;
|
||||
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\opencase_entities\Entity;
|
||||
|
||||
use Drupal\Core\Config\Entity\ConfigEntityInterface;
|
||||
|
||||
/**
|
||||
* Provides an interface for defining Organisation Relation type entities.
|
||||
*/
|
||||
interface OCOrganisationRelationTypeInterface extends ConfigEntityInterface {
|
||||
|
||||
// Add get/set methods for your configuration properties here.
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\opencase_entities\Entity;
|
||||
|
||||
use Drupal\views\EntityViewsData;
|
||||
|
||||
/**
|
||||
* Provides Views data for Organisation Relation entities.
|
||||
*/
|
||||
class OCOrganisationRelationViewsData extends EntityViewsData {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getViewsData() {
|
||||
$data = parent::getViewsData();
|
||||
|
||||
// Additional information for Views integration, such as table joins, can be
|
||||
// put here.
|
||||
return $data;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\opencase_entities\Form;
|
||||
|
||||
use Drupal\Core\Entity\ContentEntityDeleteForm;
|
||||
|
||||
/**
|
||||
* Provides a form for deleting Organisation Relation entities.
|
||||
*
|
||||
* @ingroup opencase_entities
|
||||
*/
|
||||
class OCOrganisationRelationDeleteForm extends ContentEntityDeleteForm {
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\opencase_entities\Form;
|
||||
|
||||
use Drupal\Core\Entity\ContentEntityForm;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
* Form controller for Organisation Relation edit forms.
|
||||
*
|
||||
* @ingroup opencase_entities
|
||||
*/
|
||||
class OCOrganisationRelationForm extends ContentEntityForm {
|
||||
|
||||
/**
|
||||
* The current user account.
|
||||
*
|
||||
* @var \Drupal\Core\Session\AccountProxyInterface
|
||||
*/
|
||||
protected $account;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container) {
|
||||
// Instantiates this form class.
|
||||
$instance = parent::create($container);
|
||||
$instance->account = $container->get('current_user');
|
||||
return $instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state) {
|
||||
/* @var \Drupal\opencase_entities\Entity\OCOrganisationRelation $entity */
|
||||
$form = parent::buildForm($form, $form_state);
|
||||
|
||||
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:
|
||||
$this->messenger()->addMessage($this->t('Created the %label Organisation Relation.', [
|
||||
'%label' => $entity->label(),
|
||||
]));
|
||||
break;
|
||||
|
||||
default:
|
||||
$this->messenger()->addMessage($this->t('Saved the %label Organisation Relation.', [
|
||||
'%label' => $entity->label(),
|
||||
]));
|
||||
}
|
||||
$form_state->setRedirect('entity.oc_organisation_relation.canonical', ['oc_organisation_relation' => $entity->id()]);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\opencase_entities\Form;
|
||||
|
||||
use Drupal\Core\Form\FormBase;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
|
||||
/**
|
||||
* Class OCOrganisationRelationSettingsForm.
|
||||
*
|
||||
* @ingroup opencase_entities
|
||||
*/
|
||||
class OCOrganisationRelationSettingsForm extends FormBase {
|
||||
|
||||
/**
|
||||
* Returns a unique string identifying the form.
|
||||
*
|
||||
* @return string
|
||||
* The unique string identifying the form.
|
||||
*/
|
||||
public function getFormId() {
|
||||
return 'ocorganisationrelation_settings';
|
||||
}
|
||||
|
||||
/**
|
||||
* Form submission handler.
|
||||
*
|
||||
* @param array $form
|
||||
* An associative array containing the structure of the form.
|
||||
* @param \Drupal\Core\Form\FormStateInterface $form_state
|
||||
* The current state of the form.
|
||||
*/
|
||||
public function submitForm(array &$form, FormStateInterface $form_state) {
|
||||
// Empty implementation of the abstract submit class.
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines the settings form for Organisation Relation entities.
|
||||
*
|
||||
* @param array $form
|
||||
* An associative array containing the structure of the form.
|
||||
* @param \Drupal\Core\Form\FormStateInterface $form_state
|
||||
* The current state of the form.
|
||||
*
|
||||
* @return array
|
||||
* Form definition array.
|
||||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state) {
|
||||
$form['ocorganisationrelation_settings']['#markup'] = 'Settings form for Organisation Relation entities. Manage field settings here.';
|
||||
return $form;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\opencase_entities\Form;
|
||||
|
||||
use Drupal\Core\Entity\EntityConfirmFormBase;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Url;
|
||||
|
||||
/**
|
||||
* Builds the form to delete Organisation Relation type entities.
|
||||
*/
|
||||
class OCOrganisationRelationTypeDeleteForm extends EntityConfirmFormBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getQuestion() {
|
||||
return $this->t('Are you sure you want to delete %name?', ['%name' => $this->entity->label()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getCancelUrl() {
|
||||
return new Url('entity.oc_organisation_relation_type.collection');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getConfirmText() {
|
||||
return $this->t('Delete');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function submitForm(array &$form, FormStateInterface $form_state) {
|
||||
$this->entity->delete();
|
||||
|
||||
$this->messenger()->addMessage(
|
||||
$this->t('content @type: deleted @label.', [
|
||||
'@type' => $this->entity->bundle(),
|
||||
'@label' => $this->entity->label(),
|
||||
])
|
||||
);
|
||||
|
||||
$form_state->setRedirectUrl($this->getCancelUrl());
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\opencase_entities\Form;
|
||||
|
||||
use Drupal\Core\Entity\EntityForm;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
|
||||
/**
|
||||
* Class OCOrganisationRelationTypeForm.
|
||||
*/
|
||||
class OCOrganisationRelationTypeForm extends EntityForm {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function form(array $form, FormStateInterface $form_state) {
|
||||
$form = parent::form($form, $form_state);
|
||||
|
||||
$oc_organisation_relation_type = $this->entity;
|
||||
$form['label'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => $this->t('Label'),
|
||||
'#maxlength' => 255,
|
||||
'#default_value' => $oc_organisation_relation_type->label(),
|
||||
'#description' => $this->t("Label for the Organisation Relation type."),
|
||||
'#required' => TRUE,
|
||||
];
|
||||
|
||||
$form['id'] = [
|
||||
'#type' => 'machine_name',
|
||||
'#default_value' => $oc_organisation_relation_type->id(),
|
||||
'#machine_name' => [
|
||||
'exists' => '\Drupal\opencase_entities\Entity\OCOrganisationRelationType::load',
|
||||
],
|
||||
'#disabled' => !$oc_organisation_relation_type->isNew(),
|
||||
];
|
||||
|
||||
/* You will need additional form elements for your custom properties. */
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function save(array $form, FormStateInterface $form_state) {
|
||||
$oc_organisation_relation_type = $this->entity;
|
||||
$status = $oc_organisation_relation_type->save();
|
||||
|
||||
switch ($status) {
|
||||
case SAVED_NEW:
|
||||
$this->messenger()->addMessage($this->t('Created the %label Organisation Relation type.', [
|
||||
'%label' => $oc_organisation_relation_type->label(),
|
||||
]));
|
||||
break;
|
||||
|
||||
default:
|
||||
$this->messenger()->addMessage($this->t('Saved the %label Organisation Relation type.', [
|
||||
'%label' => $oc_organisation_relation_type->label(),
|
||||
]));
|
||||
}
|
||||
$form_state->setRedirectUrl($oc_organisation_relation_type->toUrl('collection'));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\opencase_entities;
|
||||
|
||||
use Drupal\Core\Entity\EntityAccessControlHandler;
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
use Drupal\Core\Session\AccountInterface;
|
||||
use Drupal\Core\Access\AccessResult;
|
||||
|
||||
/**
|
||||
* Access controller for the Organisation Relation entity.
|
||||
*
|
||||
* @see \Drupal\opencase_entities\Entity\OCOrganisationRelation.
|
||||
*/
|
||||
class OCOrganisationRelationAccessControlHandler extends EntityAccessControlHandler {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
|
||||
/** @var \Drupal\opencase_entities\Entity\OCOrganisationRelationInterface $entity */
|
||||
|
||||
switch ($operation) {
|
||||
|
||||
case 'view':
|
||||
|
||||
if (!$entity->isPublished()) {
|
||||
return AccessResult::allowedIfHasPermission($account, 'view unpublished organisation relation entities');
|
||||
}
|
||||
|
||||
|
||||
return AccessResult::allowedIfHasPermission($account, 'view published organisation relation entities');
|
||||
|
||||
case 'update':
|
||||
|
||||
return AccessResult::allowedIfHasPermission($account, 'edit organisation relation entities');
|
||||
|
||||
case 'delete':
|
||||
|
||||
return AccessResult::allowedIfHasPermission($account, 'delete organisation relation entities');
|
||||
}
|
||||
|
||||
// Unknown operation, no opinion.
|
||||
return AccessResult::neutral();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) {
|
||||
return AccessResult::allowedIfHasPermission($account, 'add organisation relation entities');
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\opencase_entities;
|
||||
|
||||
use Drupal\Core\Entity\EntityTypeInterface;
|
||||
use Drupal\Core\Entity\Routing\AdminHtmlRouteProvider;
|
||||
use Symfony\Component\Routing\Route;
|
||||
|
||||
/**
|
||||
* Provides routes for Organisation Relation entities.
|
||||
*
|
||||
* @see \Drupal\Core\Entity\Routing\AdminHtmlRouteProvider
|
||||
* @see \Drupal\Core\Entity\Routing\DefaultHtmlRouteProvider
|
||||
*/
|
||||
class OCOrganisationRelationHtmlRouteProvider extends AdminHtmlRouteProvider {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getRoutes(EntityTypeInterface $entity_type) {
|
||||
$collection = parent::getRoutes($entity_type);
|
||||
|
||||
$entity_type_id = $entity_type->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\opencase_entities\Form\OCOrganisationRelationSettingsForm',
|
||||
'_title' => "{$entity_type->getLabel()} settings",
|
||||
])
|
||||
->setRequirement('_permission', $entity_type->getAdminPermission())
|
||||
->setOption('_admin_route', TRUE);
|
||||
|
||||
return $route;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\opencase_entities;
|
||||
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
use Drupal\Core\Entity\EntityListBuilder;
|
||||
use Drupal\Core\Link;
|
||||
|
||||
/**
|
||||
* Defines a class to build a listing of Organisation Relation entities.
|
||||
*
|
||||
* @ingroup opencase_entities
|
||||
*/
|
||||
class OCOrganisationRelationListBuilder extends EntityListBuilder {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildHeader() {
|
||||
$header['id'] = $this->t('Organisation Relation ID');
|
||||
$header['name'] = $this->t('Name');
|
||||
return $header + parent::buildHeader();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildRow(EntityInterface $entity) {
|
||||
/* @var \Drupal\opencase_entities\Entity\OCOrganisationRelation $entity */
|
||||
$row['id'] = $entity->id();
|
||||
$row['name'] = Link::createFromRoute(
|
||||
$entity->label(),
|
||||
'entity.oc_organisation_relation.edit_form',
|
||||
['oc_organisation_relation' => $entity->id()]
|
||||
);
|
||||
return $row + parent::buildRow($entity);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\opencase_entities;
|
||||
|
||||
use Drupal\Core\Entity\EntityTypeInterface;
|
||||
use Drupal\Core\Entity\Routing\AdminHtmlRouteProvider;
|
||||
|
||||
/**
|
||||
* Provides routes for Organisation Relation type entities.
|
||||
*
|
||||
* @see Drupal\Core\Entity\Routing\AdminHtmlRouteProvider
|
||||
* @see Drupal\Core\Entity\Routing\DefaultHtmlRouteProvider
|
||||
*/
|
||||
class OCOrganisationRelationTypeHtmlRouteProvider extends AdminHtmlRouteProvider {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getRoutes(EntityTypeInterface $entity_type) {
|
||||
$collection = parent::getRoutes($entity_type);
|
||||
|
||||
// Provide your custom entity routes here.
|
||||
return $collection;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\opencase_entities;
|
||||
|
||||
use Drupal\Core\Config\Entity\ConfigEntityListBuilder;
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
|
||||
/**
|
||||
* Provides a listing of Organisation Relation type entities.
|
||||
*/
|
||||
class OCOrganisationRelationTypeListBuilder extends ConfigEntityListBuilder {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildHeader() {
|
||||
$header['label'] = $this->t('Organisation Relation 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);
|
||||
}
|
||||
|
||||
}
|
@ -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_oc_organisation_relation_content_add_list()
|
||||
*
|
||||
* @ingroup themeable
|
||||
*/
|
||||
#}
|
||||
{% spaceless %}
|
||||
<dl>
|
||||
{% for type in types %}
|
||||
<dt>{{ type.link }}</dt>
|
||||
{% endfor %}
|
||||
</dl>
|
||||
{% endspaceless %}
|
@ -0,0 +1,22 @@
|
||||
{#
|
||||
/**
|
||||
* @file oc_organisation_relation.html.twig
|
||||
* Default theme implementation to present Organisation Relation data.
|
||||
*
|
||||
* This template is used when viewing Organisation Relation 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_oc_organisation_relation()
|
||||
*
|
||||
* @ingroup themeable
|
||||
*/
|
||||
#}
|
||||
<div{{ attributes.addClass('oc_organisation_relation') }}>
|
||||
{% if content %}
|
||||
{{- content -}}
|
||||
{% endif %}
|
||||
</div>
|
@ -2,7 +2,7 @@ name: 'OpenCase'
|
||||
type: module
|
||||
description: 'Simple Case Management'
|
||||
core: 8.x
|
||||
version: 8.x-2.0.1
|
||||
version: 8.x-2.0.2
|
||||
package: 'OpenCase'
|
||||
dependencies:
|
||||
- opencase_entities
|
||||
|
Reference in New Issue
Block a user