comparison core/modules/taxonomy/src/Entity/Term.php @ 5:12f9dff5fda9 tip

Update to Drupal core 8.7.1
author Chris Cannam
date Thu, 09 May 2019 15:34:47 +0100
parents a9cd425dd02b
children
comparison
equal deleted inserted replaced
4:a9cd425dd02b 5:12f9dff5fda9
1 <?php 1 <?php
2 2
3 namespace Drupal\taxonomy\Entity; 3 namespace Drupal\taxonomy\Entity;
4 4
5 use Drupal\Core\Entity\ContentEntityBase; 5 use Drupal\Core\Entity\EditorialContentEntityBase;
6 use Drupal\Core\Entity\EntityChangedTrait;
7 use Drupal\Core\Entity\EntityPublishedTrait;
8 use Drupal\Core\Entity\EntityStorageInterface; 6 use Drupal\Core\Entity\EntityStorageInterface;
9 use Drupal\Core\Entity\EntityTypeInterface; 7 use Drupal\Core\Entity\EntityTypeInterface;
10 use Drupal\Core\Field\BaseFieldDefinition; 8 use Drupal\Core\Field\BaseFieldDefinition;
11 use Drupal\taxonomy\TermInterface; 9 use Drupal\taxonomy\TermInterface;
12 use Drupal\user\StatusItem; 10 use Drupal\user\StatusItem;
38 * }, 36 * },
39 * "translation" = "Drupal\taxonomy\TermTranslationHandler" 37 * "translation" = "Drupal\taxonomy\TermTranslationHandler"
40 * }, 38 * },
41 * base_table = "taxonomy_term_data", 39 * base_table = "taxonomy_term_data",
42 * data_table = "taxonomy_term_field_data", 40 * data_table = "taxonomy_term_field_data",
41 * revision_table = "taxonomy_term_revision",
42 * revision_data_table = "taxonomy_term_field_revision",
43 * uri_callback = "taxonomy_term_uri", 43 * uri_callback = "taxonomy_term_uri",
44 * translatable = TRUE, 44 * translatable = TRUE,
45 * entity_keys = { 45 * entity_keys = {
46 * "id" = "tid", 46 * "id" = "tid",
47 * "revision" = "revision_id",
47 * "bundle" = "vid", 48 * "bundle" = "vid",
48 * "label" = "name", 49 * "label" = "name",
49 * "langcode" = "langcode", 50 * "langcode" = "langcode",
50 * "uuid" = "uuid", 51 * "uuid" = "uuid",
51 * "published" = "status", 52 * "published" = "status",
53 * },
54 * revision_metadata_keys = {
55 * "revision_user" = "revision_user",
56 * "revision_created" = "revision_created",
57 * "revision_log_message" = "revision_log_message",
52 * }, 58 * },
53 * bundle_entity_type = "taxonomy_vocabulary", 59 * bundle_entity_type = "taxonomy_vocabulary",
54 * field_ui_base_route = "entity.taxonomy_vocabulary.overview_form", 60 * field_ui_base_route = "entity.taxonomy_vocabulary.overview_form",
55 * common_reference_target = TRUE, 61 * common_reference_target = TRUE,
56 * links = { 62 * links = {
57 * "canonical" = "/taxonomy/term/{taxonomy_term}", 63 * "canonical" = "/taxonomy/term/{taxonomy_term}",
58 * "delete-form" = "/taxonomy/term/{taxonomy_term}/delete", 64 * "delete-form" = "/taxonomy/term/{taxonomy_term}/delete",
59 * "edit-form" = "/taxonomy/term/{taxonomy_term}/edit", 65 * "edit-form" = "/taxonomy/term/{taxonomy_term}/edit",
60 * "create" = "/taxonomy/term", 66 * "create" = "/taxonomy/term",
61 * }, 67 * },
62 * permission_granularity = "bundle" 68 * permission_granularity = "bundle",
69 * constraints = {
70 * "TaxonomyHierarchy" = {}
71 * }
63 * ) 72 * )
64 */ 73 */
65 class Term extends ContentEntityBase implements TermInterface { 74 class Term extends EditorialContentEntityBase implements TermInterface {
66
67 use EntityChangedTrait;
68 use EntityPublishedTrait;
69 75
70 /** 76 /**
71 * {@inheritdoc} 77 * {@inheritdoc}
72 */ 78 */
73 public static function postDelete(EntityStorageInterface $storage, array $entities) { 79 public static function postDelete(EntityStorageInterface $storage, array $entities) {
118 */ 124 */
119 public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { 125 public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
120 /** @var \Drupal\Core\Field\BaseFieldDefinition[] $fields */ 126 /** @var \Drupal\Core\Field\BaseFieldDefinition[] $fields */
121 $fields = parent::baseFieldDefinitions($entity_type); 127 $fields = parent::baseFieldDefinitions($entity_type);
122 128
123 // Add the published field.
124 $fields += static::publishedBaseFieldDefinitions($entity_type);
125 // @todo Remove the usage of StatusItem in 129 // @todo Remove the usage of StatusItem in
126 // https://www.drupal.org/project/drupal/issues/2936864. 130 // https://www.drupal.org/project/drupal/issues/2936864.
127 $fields['status']->getItemDefinition()->setClass(StatusItem::class); 131 $fields['status']->getItemDefinition()->setClass(StatusItem::class);
128 132
129 $fields['tid']->setLabel(t('Term ID')) 133 $fields['tid']->setLabel(t('Term ID'))
137 $fields['langcode']->setDescription(t('The term language code.')); 141 $fields['langcode']->setDescription(t('The term language code.'));
138 142
139 $fields['name'] = BaseFieldDefinition::create('string') 143 $fields['name'] = BaseFieldDefinition::create('string')
140 ->setLabel(t('Name')) 144 ->setLabel(t('Name'))
141 ->setTranslatable(TRUE) 145 ->setTranslatable(TRUE)
146 ->setRevisionable(TRUE)
142 ->setRequired(TRUE) 147 ->setRequired(TRUE)
143 ->setSetting('max_length', 255) 148 ->setSetting('max_length', 255)
144 ->setDisplayOptions('view', [ 149 ->setDisplayOptions('view', [
145 'label' => 'hidden', 150 'label' => 'hidden',
146 'type' => 'string', 151 'type' => 'string',
153 ->setDisplayConfigurable('form', TRUE); 158 ->setDisplayConfigurable('form', TRUE);
154 159
155 $fields['description'] = BaseFieldDefinition::create('text_long') 160 $fields['description'] = BaseFieldDefinition::create('text_long')
156 ->setLabel(t('Description')) 161 ->setLabel(t('Description'))
157 ->setTranslatable(TRUE) 162 ->setTranslatable(TRUE)
163 ->setRevisionable(TRUE)
158 ->setDisplayOptions('view', [ 164 ->setDisplayOptions('view', [
159 'label' => 'hidden', 165 'label' => 'hidden',
160 'type' => 'text_default', 166 'type' => 'text_default',
161 'weight' => 0, 167 'weight' => 0,
162 ]) 168 ])
179 ->setCardinality(BaseFieldDefinition::CARDINALITY_UNLIMITED); 185 ->setCardinality(BaseFieldDefinition::CARDINALITY_UNLIMITED);
180 186
181 $fields['changed'] = BaseFieldDefinition::create('changed') 187 $fields['changed'] = BaseFieldDefinition::create('changed')
182 ->setLabel(t('Changed')) 188 ->setLabel(t('Changed'))
183 ->setDescription(t('The time that the term was last edited.')) 189 ->setDescription(t('The time that the term was last edited.'))
184 ->setTranslatable(TRUE); 190 ->setTranslatable(TRUE)
191 ->setRevisionable(TRUE);
192
193 // @todo Keep this field hidden until we have a revision UI for terms.
194 // @see https://www.drupal.org/project/drupal/issues/2936995
195 $fields['revision_log_message']->setDisplayOptions('form', [
196 'region' => 'hidden',
197 ]);
185 198
186 return $fields; 199 return $fields;
187 } 200 }
188 201
189 /** 202 /**