Added Organisation Relation entity with update hook to install it, bumped version
This commit is contained in:
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;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user