Added actor-case relation

This commit is contained in:
2021-08-26 17:55:07 +01:00
parent 8cb50d271b
commit c7d36df842
33 changed files with 2106 additions and 1 deletions

View File

@ -0,0 +1,268 @@
<?php
namespace Drupal\opencase_cases\Entity;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\Entity\EditorialContentEntityBase;
use Drupal\Core\Entity\RevisionableInterface;
use Drupal\Core\Entity\EntityChangedTrait;
use Drupal\Core\Entity\EntityPublishedTrait;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\user\UserInterface;
/**
* Defines the Actor-Case Relation entity.
*
* @ingroup opencase_cases
*
* @ContentEntityType(
* id = "oc_actor_case_relation",
* label = @Translation("Actor-Case Relation"),
* bundle_label = @Translation("Actor-Case Relation type"),
* handlers = {
* "storage" = "Drupal\opencase_cases\OCActorCaseRelationStorage",
* "view_builder" = "Drupal\Core\Entity\EntityViewBuilder",
* "list_builder" = "Drupal\opencase_cases\OCActorCaseRelationListBuilder",
* "views_data" = "Drupal\opencase_cases\Entity\OCActorCaseRelationViewsData",
* "translation" = "Drupal\opencase_cases\OCActorCaseRelationTranslationHandler",
*
* "form" = {
* "default" = "Drupal\opencase_cases\Form\OCActorCaseRelationForm",
* "add" = "Drupal\opencase_cases\Form\OCActorCaseRelationForm",
* "edit" = "Drupal\opencase_cases\Form\OCActorCaseRelationForm",
* "delete" = "Drupal\opencase_cases\Form\OCActorCaseRelationDeleteForm",
* },
* "route_provider" = {
* "html" = "Drupal\opencase_cases\OCActorCaseRelationHtmlRouteProvider",
* },
* "access" = "Drupal\opencase_cases\OCActorCaseRelationAccessControlHandler",
* },
* base_table = "oc_actor_case_relation",
* data_table = "oc_actor_case_relation_field_data",
* revision_table = "oc_actor_case_relation_revision",
* revision_data_table = "oc_actor_case_relation_field_revision",
* translatable = TRUE,
* permission_granularity = "bundle",
* admin_permission = "administer actor-case relation entities",
* entity_keys = {
* "id" = "id",
* "revision" = "vid",
* "bundle" = "type",
* "label" = "name",
* "uuid" = "uuid",
* "uid" = "user_id",
* "langcode" = "langcode",
* "published" = "status",
* },
* links = {
* "canonical" = "/admin/structure/oc_actor_case_relation/{oc_actor_case_relation}",
* "add-page" = "/admin/structure/oc_actor_case_relation/add",
* "add-form" = "/admin/structure/oc_actor_case_relation/add/{oc_actor_case_relation_type}",
* "edit-form" = "/admin/structure/oc_actor_case_relation/{oc_actor_case_relation}/edit",
* "delete-form" = "/admin/structure/oc_actor_case_relation/{oc_actor_case_relation}/delete",
* "version-history" = "/admin/structure/oc_actor_case_relation/{oc_actor_case_relation}/revisions",
* "revision" = "/admin/structure/oc_actor_case_relation/{oc_actor_case_relation}/revisions/{oc_actor_case_relation_revision}/view",
* "revision_revert" = "/admin/structure/oc_actor_case_relation/{oc_actor_case_relation}/revisions/{oc_actor_case_relation_revision}/revert",
* "revision_delete" = "/admin/structure/oc_actor_case_relation/{oc_actor_case_relation}/revisions/{oc_actor_case_relation_revision}/delete",
* "translation_revert" = "/admin/structure/oc_actor_case_relation/{oc_actor_case_relation}/revisions/{oc_actor_case_relation_revision}/revert/{langcode}",
* "collection" = "/admin/structure/oc_actor_case_relation",
* },
* bundle_entity_type = "oc_actor_case_relation_type",
* field_ui_base_route = "entity.oc_actor_case_relation_type.edit_form"
* )
*/
class OCActorCaseRelation extends EditorialContentEntityBase implements OCActorCaseRelationInterface {
use EntityChangedTrait;
use EntityPublishedTrait;
/**
* {@inheritdoc}
*/
public static function preCreate(EntityStorageInterface $storage_controller, array &$values) {
parent::preCreate($storage_controller, $values);
$values += [
'user_id' => \Drupal::currentUser()->id(),
];
}
/**
* {@inheritdoc}
*/
protected function urlRouteParameters($rel) {
$uri_route_parameters = parent::urlRouteParameters($rel);
if ($rel === 'revision_revert' && $this instanceof RevisionableInterface) {
$uri_route_parameters[$this->getEntityTypeId() . '_revision'] = $this->getRevisionId();
}
elseif ($rel === 'revision_delete' && $this instanceof RevisionableInterface) {
$uri_route_parameters[$this->getEntityTypeId() . '_revision'] = $this->getRevisionId();
}
return $uri_route_parameters;
}
/**
* {@inheritdoc}
*/
public function preSave(EntityStorageInterface $storage) {
parent::preSave($storage);
foreach (array_keys($this->getTranslationLanguages()) as $langcode) {
$translation = $this->getTranslation($langcode);
// If no owner has been set explicitly, make the anonymous user the owner.
if (!$translation->getOwner()) {
$translation->setOwnerId(0);
}
}
// If no revision author has been set explicitly,
// make the oc_actor_case_relation owner the revision author.
if (!$this->getRevisionUser()) {
$this->setRevisionUserId($this->getOwnerId());
}
}
/**
* {@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 function getOwner() {
return $this->get('user_id')->entity;
}
/**
* {@inheritdoc}
*/
public function getOwnerId() {
return $this->get('user_id')->target_id;
}
/**
* {@inheritdoc}
*/
public function setOwnerId($uid) {
$this->set('user_id', $uid);
return $this;
}
/**
* {@inheritdoc}
*/
public function setOwner(UserInterface $account) {
$this->set('user_id', $account->id());
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['user_id'] = BaseFieldDefinition::create('entity_reference')
->setLabel(t('Authored by'))
->setDescription(t('The user ID of author of the Actor-Case Relation entity.'))
->setRevisionable(TRUE)
->setSetting('target_type', 'user')
->setSetting('handler', 'default')
->setTranslatable(TRUE)
->setDisplayOptions('view', [
'label' => 'hidden',
'type' => 'author',
'weight' => 0,
])
->setDisplayOptions('form', [
'type' => 'entity_reference_autocomplete',
'weight' => 5,
'settings' => [
'match_operator' => 'CONTAINS',
'size' => '60',
'autocomplete_type' => 'tags',
'placeholder' => '',
],
])
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE);
$fields['name'] = BaseFieldDefinition::create('string')
->setLabel(t('Name'))
->setDescription(t('The name of the Actor-Case Relation entity.'))
->setRevisionable(TRUE)
->setSettings([
'max_length' => 50,
'text_processing' => 0,
])
->setDefaultValue('')
->setDisplayOptions('view', [
'label' => 'above',
'type' => 'string',
'weight' => -4,
])
->setDisplayOptions('form', [
'type' => 'string_textfield',
'weight' => -4,
])
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE)
->setRequired(TRUE);
$fields['status']->setDescription(t('A boolean indicating whether the Actor-Case 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['revision_translation_affected'] = BaseFieldDefinition::create('boolean')
->setLabel(t('Revision translation affected'))
->setDescription(t('Indicates if the last edit of a translation belongs to current revision.'))
->setReadOnly(TRUE)
->setRevisionable(TRUE)
->setTranslatable(TRUE);
return $fields;
}
}

View File

@ -0,0 +1,98 @@
<?php
namespace Drupal\opencase_cases\Entity;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Entity\RevisionLogInterface;
use Drupal\Core\Entity\EntityChangedInterface;
use Drupal\Core\Entity\EntityPublishedInterface;
use Drupal\user\EntityOwnerInterface;
/**
* Provides an interface for defining Actor-Case Relation entities.
*
* @ingroup opencase_cases
*/
interface OCActorCaseRelationInterface extends ContentEntityInterface, RevisionLogInterface, EntityChangedInterface, EntityPublishedInterface, EntityOwnerInterface {
/**
* Add get/set methods for your configuration properties here.
*/
/**
* Gets the Actor-Case Relation name.
*
* @return string
* Name of the Actor-Case Relation.
*/
public function getName();
/**
* Sets the Actor-Case Relation name.
*
* @param string $name
* The Actor-Case Relation name.
*
* @return \Drupal\opencase_cases\Entity\OCActorCaseRelationInterface
* The called Actor-Case Relation entity.
*/
public function setName($name);
/**
* Gets the Actor-Case Relation creation timestamp.
*
* @return int
* Creation timestamp of the Actor-Case Relation.
*/
public function getCreatedTime();
/**
* Sets the Actor-Case Relation creation timestamp.
*
* @param int $timestamp
* The Actor-Case Relation creation timestamp.
*
* @return \Drupal\opencase_cases\Entity\OCActorCaseRelationInterface
* The called Actor-Case Relation entity.
*/
public function setCreatedTime($timestamp);
/**
* Gets the Actor-Case Relation revision creation timestamp.
*
* @return int
* The UNIX timestamp of when this revision was created.
*/
public function getRevisionCreationTime();
/**
* Sets the Actor-Case Relation revision creation timestamp.
*
* @param int $timestamp
* The UNIX timestamp of when this revision was created.
*
* @return \Drupal\opencase_cases\Entity\OCActorCaseRelationInterface
* The called Actor-Case Relation entity.
*/
public function setRevisionCreationTime($timestamp);
/**
* Gets the Actor-Case Relation revision author.
*
* @return \Drupal\user\UserInterface
* The user entity for the revision author.
*/
public function getRevisionUser();
/**
* Sets the Actor-Case Relation revision author.
*
* @param int $uid
* The user ID of the revision author.
*
* @return \Drupal\opencase_cases\Entity\OCActorCaseRelationInterface
* The called Actor-Case Relation entity.
*/
public function setRevisionUserId($uid);
}

View File

@ -0,0 +1,58 @@
<?php
namespace Drupal\opencase_cases\Entity;
use Drupal\Core\Config\Entity\ConfigEntityBundleBase;
/**
* Defines the Actor-Case Relation type entity.
*
* @ConfigEntityType(
* id = "oc_actor_case_relation_type",
* label = @Translation("Actor-Case Relation type"),
* handlers = {
* "view_builder" = "Drupal\Core\Entity\EntityViewBuilder",
* "list_builder" = "Drupal\opencase_cases\OCActorCaseRelationTypeListBuilder",
* "form" = {
* "add" = "Drupal\opencase_cases\Form\OCActorCaseRelationTypeForm",
* "edit" = "Drupal\opencase_cases\Form\OCActorCaseRelationTypeForm",
* "delete" = "Drupal\opencase_cases\Form\OCActorCaseRelationTypeDeleteForm"
* },
* "route_provider" = {
* "html" = "Drupal\opencase_cases\OCActorCaseRelationTypeHtmlRouteProvider",
* },
* },
* config_prefix = "oc_actor_case_relation_type",
* admin_permission = "administer site configuration",
* bundle_of = "oc_actor_case_relation",
* entity_keys = {
* "id" = "id",
* "label" = "label",
* "uuid" = "uuid"
* },
* links = {
* "canonical" = "/admin/structure/oc_actor_case_relation_type/{oc_actor_case_relation_type}",
* "add-form" = "/admin/structure/oc_actor_case_relation_type/add",
* "edit-form" = "/admin/structure/oc_actor_case_relation_type/{oc_actor_case_relation_type}/edit",
* "delete-form" = "/admin/structure/oc_actor_case_relation_type/{oc_actor_case_relation_type}/delete",
* "collection" = "/admin/structure/oc_actor_case_relation_type"
* }
* )
*/
class OCActorCaseRelationType extends ConfigEntityBundleBase implements OCActorCaseRelationTypeInterface {
/**
* The Actor-Case Relation type ID.
*
* @var string
*/
protected $id;
/**
* The Actor-Case Relation type label.
*
* @var string
*/
protected $label;
}

View File

@ -0,0 +1,13 @@
<?php
namespace Drupal\opencase_cases\Entity;
use Drupal\Core\Config\Entity\ConfigEntityInterface;
/**
* Provides an interface for defining Actor-Case Relation type entities.
*/
interface OCActorCaseRelationTypeInterface extends ConfigEntityInterface {
// Add get/set methods for your configuration properties here.
}

View File

@ -0,0 +1,23 @@
<?php
namespace Drupal\opencase_cases\Entity;
use Drupal\views\EntityViewsData;
/**
* Provides Views data for Actor-Case Relation entities.
*/
class OCActorCaseRelationViewsData extends EntityViewsData {
/**
* {@inheritdoc}
*/
public function getViewsData() {
$data = parent::getViewsData();
// Additional information for Views integration, such as table joins, can be
// put here.
return $data;
}
}