made fields configurable for case and sub cases
This commit is contained in:
parent
2f06caa261
commit
489f4c0c94
@ -75,22 +75,25 @@ use Drupal\user\UserInterface;
|
||||
* field_ui_base_route = "entity.oc_case_type.edit_form"
|
||||
* )
|
||||
*/
|
||||
class OCCase extends RevisionableContentEntityBase implements OCCaseInterface {
|
||||
class OCCase extends RevisionableContentEntityBase implements OCCaseInterface
|
||||
{
|
||||
|
||||
use EntityChangedTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function preCreate(EntityStorageInterface $storage_controller, array &$values) {
|
||||
public static function preCreate(EntityStorageInterface $storage_controller, array &$values)
|
||||
{
|
||||
parent::preCreate($storage_controller, $values);
|
||||
$values += [
|
||||
'user_id' => \Drupal::currentUser()->id(),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
public static function defaultTarget() {
|
||||
|
||||
public static function defaultTarget()
|
||||
{
|
||||
if (opencase_entities_get('target_id')) return [opencase_entities_get('target_id')];
|
||||
else return [];
|
||||
}
|
||||
@ -98,13 +101,13 @@ class OCCase extends RevisionableContentEntityBase implements OCCaseInterface {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function urlRouteParameters($rel) {
|
||||
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) {
|
||||
} elseif ($rel === 'revision_delete' && $this instanceof RevisionableInterface) {
|
||||
$uri_route_parameters[$this->getEntityTypeId() . '_revision'] = $this->getRevisionId();
|
||||
}
|
||||
|
||||
@ -114,7 +117,8 @@ class OCCase extends RevisionableContentEntityBase implements OCCaseInterface {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function preSave(EntityStorageInterface $storage) {
|
||||
public function preSave(EntityStorageInterface $storage)
|
||||
{
|
||||
parent::preSave($storage);
|
||||
|
||||
foreach (array_keys($this->getTranslationLanguages()) as $langcode) {
|
||||
@ -136,14 +140,16 @@ class OCCase extends RevisionableContentEntityBase implements OCCaseInterface {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getName() {
|
||||
public function getName()
|
||||
{
|
||||
return $this->get('name')->value;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setName($name) {
|
||||
public function setName($name)
|
||||
{
|
||||
$this->set('name', $name);
|
||||
return $this;
|
||||
}
|
||||
@ -151,14 +157,16 @@ class OCCase extends RevisionableContentEntityBase implements OCCaseInterface {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getCreatedTime() {
|
||||
public function getCreatedTime()
|
||||
{
|
||||
return $this->get('created')->value;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setCreatedTime($timestamp) {
|
||||
public function setCreatedTime($timestamp)
|
||||
{
|
||||
$this->set('created', $timestamp);
|
||||
return $this;
|
||||
}
|
||||
@ -166,21 +174,24 @@ class OCCase extends RevisionableContentEntityBase implements OCCaseInterface {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getOwner() {
|
||||
public function getOwner()
|
||||
{
|
||||
return $this->get('user_id')->entity;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getOwnerId() {
|
||||
public function getOwnerId()
|
||||
{
|
||||
return $this->get('user_id')->target_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setOwnerId($uid) {
|
||||
public function setOwnerId($uid)
|
||||
{
|
||||
$this->set('user_id', $uid);
|
||||
return $this;
|
||||
}
|
||||
@ -188,7 +199,8 @@ class OCCase extends RevisionableContentEntityBase implements OCCaseInterface {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setOwner(UserInterface $account) {
|
||||
public function setOwner(UserInterface $account)
|
||||
{
|
||||
$this->set('user_id', $account->id());
|
||||
return $this;
|
||||
}
|
||||
@ -196,24 +208,26 @@ class OCCase extends RevisionableContentEntityBase implements OCCaseInterface {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isPublished() {
|
||||
return (bool) $this->getEntityKey('status');
|
||||
public function isPublished()
|
||||
{
|
||||
return (bool)$this->getEntityKey('status');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setPublished($published) {
|
||||
public function setPublished($published)
|
||||
{
|
||||
$this->set('status', $published ? TRUE : FALSE);
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
|
||||
public static function baseFieldDefinitions(EntityTypeInterface $entity_type)
|
||||
{
|
||||
$fields = parent::baseFieldDefinitions($entity_type);
|
||||
|
||||
// not currently used. Will add form and view settings when ready
|
||||
@ -221,7 +235,8 @@ class OCCase extends RevisionableContentEntityBase implements OCCaseInterface {
|
||||
->setLabel(t('Visible'))
|
||||
->setDescription('If this box is not ticked this record will be hidden from view for most users. Users with access to unpublished entities will be able to restore it if needed.')
|
||||
->setRevisionable(TRUE)
|
||||
->setDisplayConfigurable("form", TRUE)
|
||||
->setDisplayConfigurable('form', true)
|
||||
->setDisplayConfigurable('view', true)
|
||||
->setDefaultValue(TRUE);
|
||||
|
||||
$fields['user_id'] = BaseFieldDefinition::create('entity_reference')
|
||||
@ -232,22 +247,17 @@ class OCCase extends RevisionableContentEntityBase implements OCCaseInterface {
|
||||
->setSetting('handler', 'default')
|
||||
->setTranslatable(TRUE)
|
||||
->setDisplayConfigurable('form', true)
|
||||
->setDisplayConfigurable('view', true)
|
||||
->setDisplayOptions('view', [
|
||||
'label' => 'above',
|
||||
'type' => 'author',
|
||||
'weight' => 80,
|
||||
]);
|
||||
->setDisplayConfigurable('view', true);
|
||||
|
||||
|
||||
$fields['oc_target'] = BaseFieldDefinition::create('entity_reference')
|
||||
->setLabel(t('Target'))
|
||||
->setRevisionable(TRUE)
|
||||
->setSetting('target_type', 'oc_actor')
|
||||
->setSetting('handler', 'default')
|
||||
->setDefaultValueCallback('\Drupal\opencase_cases\Entity\OCCase::defaultTarget')
|
||||
->setDisplayConfigurable('form', true)
|
||||
->setDisplayConfigurable('view', true);
|
||||
->setLabel(t('Target'))
|
||||
->setRevisionable(TRUE)
|
||||
->setSetting('target_type', 'oc_actor')
|
||||
->setSetting('handler', 'default')
|
||||
->setDefaultValueCallback('\Drupal\opencase_cases\Entity\OCCase::defaultTarget')
|
||||
->setDisplayConfigurable('form', true)
|
||||
->setDisplayConfigurable('view', true);
|
||||
|
||||
$fields['name'] = BaseFieldDefinition::create('string')
|
||||
->setLabel(t('Title'))
|
||||
@ -257,14 +267,8 @@ class OCCase extends RevisionableContentEntityBase implements OCCaseInterface {
|
||||
'text_processing' => 0,
|
||||
])
|
||||
->setDefaultValue('')
|
||||
->setDisplayOptions('view', [
|
||||
'label' => 'hidden',
|
||||
'type' => 'string',
|
||||
])
|
||||
->setDisplayOptions('form', [
|
||||
'type' => 'string_textfield',
|
||||
'weight' => -100,
|
||||
])
|
||||
->setDisplayConfigurable('form', true)
|
||||
->setDisplayConfigurable('view', true)
|
||||
->setRequired(TRUE);
|
||||
|
||||
|
||||
@ -278,18 +282,7 @@ class OCCase extends RevisionableContentEntityBase implements OCCaseInterface {
|
||||
->setSetting('uri_scheme', 'private')
|
||||
->setCardinality(-1)
|
||||
->setDisplayConfigurable('form', true)
|
||||
->setDisplayConfigurable('view', true)
|
||||
->setDisplayOptions('form', [
|
||||
'type' => 'file_generic',
|
||||
'weight' => -1,
|
||||
'settings' => [
|
||||
'progress_indicator' => 'throbber',
|
||||
],
|
||||
])
|
||||
->setDisplayOptions('view', [
|
||||
'label' => 'above',
|
||||
'settings' => ['use_description_as_link_text' => 'true']
|
||||
]);
|
||||
->setDisplayConfigurable('view', true);
|
||||
|
||||
$fields['created'] = BaseFieldDefinition::create('created')
|
||||
->setLabel(t('Created on'))
|
||||
@ -321,12 +314,13 @@ class OCCase extends RevisionableContentEntityBase implements OCCaseInterface {
|
||||
|
||||
|
||||
$fields['total_fee'] = BaseFieldDefinition::create('decimal')
|
||||
->setLabel(t('Total Fee'))
|
||||
->setRevisionable(TRUE)
|
||||
->setSettings([
|
||||
'prefix' => '£',
|
||||
])
|
||||
->SetDisplayConfigurable("view", true);
|
||||
->setLabel(t('Total Fee'))
|
||||
->setRevisionable(TRUE)
|
||||
->setSettings([
|
||||
'prefix' => '£',
|
||||
])
|
||||
->setDisplayConfigurable('form', true)
|
||||
->setDisplayConfigurable('view', true);
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
@ -206,21 +206,6 @@ class OCCaseFee extends EditorialContentEntityBase implements OCCaseFeeInterface
|
||||
->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);
|
||||
|
||||
@ -233,15 +218,6 @@ class OCCaseFee extends EditorialContentEntityBase implements OCCaseFeeInterface
|
||||
'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);
|
||||
|
@ -77,7 +77,8 @@ use Drupal\user\UserInterface;
|
||||
* field_ui_base_route = "entity.oc_case_provision_type.edit_form"
|
||||
* )
|
||||
*/
|
||||
class OCCaseProvision extends EditorialContentEntityBase implements OCCaseProvisionInterface {
|
||||
class OCCaseProvision extends EditorialContentEntityBase implements OCCaseProvisionInterface
|
||||
{
|
||||
|
||||
use EntityChangedTrait;
|
||||
use EntityPublishedTrait;
|
||||
@ -85,7 +86,8 @@ class OCCaseProvision extends EditorialContentEntityBase implements OCCaseProvis
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function preCreate(EntityStorageInterface $storage_controller, array &$values) {
|
||||
public static function preCreate(EntityStorageInterface $storage_controller, array &$values)
|
||||
{
|
||||
parent::preCreate($storage_controller, $values);
|
||||
$values += [
|
||||
'user_id' => \Drupal::currentUser()->id(),
|
||||
@ -95,13 +97,13 @@ class OCCaseProvision extends EditorialContentEntityBase implements OCCaseProvis
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function urlRouteParameters($rel) {
|
||||
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) {
|
||||
} elseif ($rel === 'revision_delete' && $this instanceof RevisionableInterface) {
|
||||
$uri_route_parameters[$this->getEntityTypeId() . '_revision'] = $this->getRevisionId();
|
||||
}
|
||||
|
||||
@ -111,7 +113,8 @@ class OCCaseProvision extends EditorialContentEntityBase implements OCCaseProvis
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function preSave(EntityStorageInterface $storage) {
|
||||
public function preSave(EntityStorageInterface $storage)
|
||||
{
|
||||
parent::preSave($storage);
|
||||
|
||||
foreach (array_keys($this->getTranslationLanguages()) as $langcode) {
|
||||
@ -133,14 +136,16 @@ class OCCaseProvision extends EditorialContentEntityBase implements OCCaseProvis
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getName() {
|
||||
public function getName()
|
||||
{
|
||||
return $this->get('name')->value;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setName($name) {
|
||||
public function setName($name)
|
||||
{
|
||||
$this->set('name', $name);
|
||||
return $this;
|
||||
}
|
||||
@ -148,14 +153,16 @@ class OCCaseProvision extends EditorialContentEntityBase implements OCCaseProvis
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getCreatedTime() {
|
||||
public function getCreatedTime()
|
||||
{
|
||||
return $this->get('created')->value;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setCreatedTime($timestamp) {
|
||||
public function setCreatedTime($timestamp)
|
||||
{
|
||||
$this->set('created', $timestamp);
|
||||
return $this;
|
||||
}
|
||||
@ -163,21 +170,24 @@ class OCCaseProvision extends EditorialContentEntityBase implements OCCaseProvis
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getOwner() {
|
||||
public function getOwner()
|
||||
{
|
||||
return $this->get('user_id')->entity;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getOwnerId() {
|
||||
public function getOwnerId()
|
||||
{
|
||||
return $this->get('user_id')->target_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setOwnerId($uid) {
|
||||
public function setOwnerId($uid)
|
||||
{
|
||||
$this->set('user_id', $uid);
|
||||
return $this;
|
||||
}
|
||||
@ -185,7 +195,8 @@ class OCCaseProvision extends EditorialContentEntityBase implements OCCaseProvis
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setOwner(UserInterface $account) {
|
||||
public function setOwner(UserInterface $account)
|
||||
{
|
||||
$this->set('user_id', $account->id());
|
||||
return $this;
|
||||
}
|
||||
@ -193,7 +204,8 @@ class OCCaseProvision extends EditorialContentEntityBase implements OCCaseProvis
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
|
||||
public static function baseFieldDefinitions(EntityTypeInterface $entity_type)
|
||||
{
|
||||
$fields = parent::baseFieldDefinitions($entity_type);
|
||||
|
||||
// Add the published field.
|
||||
@ -206,21 +218,6 @@ class OCCaseProvision extends EditorialContentEntityBase implements OCCaseProvis
|
||||
->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);
|
||||
|
||||
@ -233,25 +230,17 @@ class OCCaseProvision extends EditorialContentEntityBase implements OCCaseProvis
|
||||
'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'] = BaseFieldDefinition::create('boolean')
|
||||
$fields['status'] = BaseFieldDefinition::create('boolean')
|
||||
->setLabel(t('Visible'))
|
||||
->setDescription('If this box is not ticked this record will be hidden from view for most users. Users with access to unpublished entities will be able to restore it if needed.')
|
||||
->setRevisionable(TRUE)
|
||||
->setDisplayConfigurable('form', TRUE)
|
||||
->setDisplayConfigurable('form', true)
|
||||
->setDisplayConfigurable('view', true)
|
||||
->setDefaultValue(TRUE);
|
||||
|
||||
|
||||
@ -298,7 +287,7 @@ class OCCaseProvision extends EditorialContentEntityBase implements OCCaseProvis
|
||||
->setDisplayConfigurable("form", true)
|
||||
->setRequired(TRUE);
|
||||
|
||||
$fields['oc_case_provider_role'] = \Drupal\Core\Field\BaseFieldDefinition::create('entity_reference')
|
||||
$fields['oc_case_provider_role'] = \Drupal\Core\Field\BaseFieldDefinition::create('entity_reference')
|
||||
->setLabel(t('Role'))
|
||||
->setSetting('target_type', 'taxonomy_term')
|
||||
->setSetting('handler_settings', ['target_bundles' => ['oc_case_provider_role' => 'oc_case_provider_role']])
|
||||
|
Reference in New Issue
Block a user