Mercurial > hg > cmmr2012-drupal-site
comparison core/modules/content_moderation/src/Entity/ContentModerationState.php @ 5:12f9dff5fda9 tip
Update to Drupal core 8.7.1
author | Chris Cannam |
---|---|
date | Thu, 09 May 2019 15:34:47 +0100 |
parents | c75dbcec494b |
children |
comparison
equal
deleted
inserted
replaced
4:a9cd425dd02b | 5:12f9dff5fda9 |
---|---|
5 use Drupal\Core\Entity\ContentEntityBase; | 5 use Drupal\Core\Entity\ContentEntityBase; |
6 use Drupal\Core\Entity\EntityInterface; | 6 use Drupal\Core\Entity\EntityInterface; |
7 use Drupal\Core\Entity\EntityTypeInterface; | 7 use Drupal\Core\Entity\EntityTypeInterface; |
8 use Drupal\Core\Field\BaseFieldDefinition; | 8 use Drupal\Core\Field\BaseFieldDefinition; |
9 use Drupal\Core\TypedData\TranslatableInterface; | 9 use Drupal\Core\TypedData\TranslatableInterface; |
10 use Drupal\user\UserInterface; | 10 use Drupal\user\EntityOwnerTrait; |
11 | 11 |
12 /** | 12 /** |
13 * Defines the Content moderation state entity. | 13 * Defines the Content moderation state entity. |
14 * | 14 * |
15 * @ContentEntityType( | 15 * @ContentEntityType( |
35 * entity_keys = { | 35 * entity_keys = { |
36 * "id" = "id", | 36 * "id" = "id", |
37 * "revision" = "revision_id", | 37 * "revision" = "revision_id", |
38 * "uuid" = "uuid", | 38 * "uuid" = "uuid", |
39 * "uid" = "uid", | 39 * "uid" = "uid", |
40 * "owner" = "uid", | |
40 * "langcode" = "langcode", | 41 * "langcode" = "langcode", |
41 * } | 42 * } |
42 * ) | 43 * ) |
43 * | 44 * |
44 * @internal | 45 * @internal |
46 * alter the moderation state of an entity. Instead, the computed | 47 * alter the moderation state of an entity. Instead, the computed |
47 * moderation_state field should be set on the entity directly. | 48 * moderation_state field should be set on the entity directly. |
48 */ | 49 */ |
49 class ContentModerationState extends ContentEntityBase implements ContentModerationStateInterface { | 50 class ContentModerationState extends ContentEntityBase implements ContentModerationStateInterface { |
50 | 51 |
52 use EntityOwnerTrait; | |
53 | |
51 /** | 54 /** |
52 * {@inheritdoc} | 55 * {@inheritdoc} |
53 */ | 56 */ |
54 public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { | 57 public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { |
55 $fields = parent::baseFieldDefinitions($entity_type); | 58 $fields = parent::baseFieldDefinitions($entity_type); |
56 | 59 $fields += static::ownerBaseFieldDefinitions($entity_type); |
57 $fields['uid'] = BaseFieldDefinition::create('entity_reference') | 60 |
61 $fields['uid'] | |
58 ->setLabel(t('User')) | 62 ->setLabel(t('User')) |
59 ->setDescription(t('The username of the entity creator.')) | 63 ->setDescription(t('The username of the entity creator.')) |
60 ->setSetting('target_type', 'user') | |
61 ->setDefaultValueCallback('Drupal\content_moderation\Entity\ContentModerationState::getCurrentUserId') | |
62 ->setTranslatable(TRUE) | |
63 ->setRevisionable(TRUE); | 64 ->setRevisionable(TRUE); |
64 | 65 |
65 $fields['workflow'] = BaseFieldDefinition::create('entity_reference') | 66 $fields['workflow'] = BaseFieldDefinition::create('entity_reference') |
66 ->setLabel(t('Workflow')) | 67 ->setLabel(t('Workflow')) |
67 ->setDescription(t('The workflow the moderation state is in.')) | 68 ->setDescription(t('The workflow the moderation state is in.')) |
94 ->setDescription(t('The revision ID of the content entity this moderation state is for.')) | 95 ->setDescription(t('The revision ID of the content entity this moderation state is for.')) |
95 ->setRequired(TRUE) | 96 ->setRequired(TRUE) |
96 ->setRevisionable(TRUE); | 97 ->setRevisionable(TRUE); |
97 | 98 |
98 return $fields; | 99 return $fields; |
99 } | |
100 | |
101 /** | |
102 * {@inheritdoc} | |
103 */ | |
104 public function getOwner() { | |
105 return $this->get('uid')->entity; | |
106 } | |
107 | |
108 /** | |
109 * {@inheritdoc} | |
110 */ | |
111 public function getOwnerId() { | |
112 return $this->getEntityKey('uid'); | |
113 } | |
114 | |
115 /** | |
116 * {@inheritdoc} | |
117 */ | |
118 public function setOwnerId($uid) { | |
119 $this->set('uid', $uid); | |
120 return $this; | |
121 } | |
122 | |
123 /** | |
124 * {@inheritdoc} | |
125 */ | |
126 public function setOwner(UserInterface $account) { | |
127 $this->set('uid', $account->id()); | |
128 return $this; | |
129 } | 100 } |
130 | 101 |
131 /** | 102 /** |
132 * Creates or updates an entity's moderation state whilst saving that entity. | 103 * Creates or updates an entity's moderation state whilst saving that entity. |
133 * | 104 * |
183 /** | 154 /** |
184 * Default value callback for the 'uid' base field definition. | 155 * Default value callback for the 'uid' base field definition. |
185 * | 156 * |
186 * @see \Drupal\content_moderation\Entity\ContentModerationState::baseFieldDefinitions() | 157 * @see \Drupal\content_moderation\Entity\ContentModerationState::baseFieldDefinitions() |
187 * | 158 * |
159 * @deprecated The ::getCurrentUserId method is deprecated in 8.6.x and will | |
160 * be removed before 9.0.0. | |
161 * | |
188 * @return array | 162 * @return array |
189 * An array of default values. | 163 * An array of default values. |
190 */ | 164 */ |
191 public static function getCurrentUserId() { | 165 public static function getCurrentUserId() { |
166 @trigger_error('The ::getCurrentUserId method is deprecated in 8.6.x and will be removed before 9.0.0.', E_USER_DEPRECATED); | |
192 return [\Drupal::currentUser()->id()]; | 167 return [\Drupal::currentUser()->id()]; |
193 } | 168 } |
194 | 169 |
195 /** | 170 /** |
196 * {@inheritdoc} | 171 * {@inheritdoc} |