Mercurial > hg > isophonics-drupal-site
comparison core/modules/node/src/Entity/Node.php @ 18:af1871eacc83
Update to Drupal core 8.7.1
author | Chris Cannam |
---|---|
date | Thu, 09 May 2019 15:33:08 +0100 |
parents | 129ea1e6d783 |
children |
comparison
equal
deleted
inserted
replaced
17:129ea1e6d783 | 18:af1871eacc83 |
---|---|
6 use Drupal\Core\Entity\EntityStorageInterface; | 6 use Drupal\Core\Entity\EntityStorageInterface; |
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\Session\AccountInterface; | 9 use Drupal\Core\Session\AccountInterface; |
10 use Drupal\node\NodeInterface; | 10 use Drupal\node\NodeInterface; |
11 use Drupal\user\UserInterface; | 11 use Drupal\user\EntityOwnerTrait; |
12 | 12 |
13 /** | 13 /** |
14 * Defines the node entity class. | 14 * Defines the node entity class. |
15 * | 15 * |
16 * @ContentEntityType( | 16 * @ContentEntityType( |
57 * "langcode" = "langcode", | 57 * "langcode" = "langcode", |
58 * "uuid" = "uuid", | 58 * "uuid" = "uuid", |
59 * "status" = "status", | 59 * "status" = "status", |
60 * "published" = "status", | 60 * "published" = "status", |
61 * "uid" = "uid", | 61 * "uid" = "uid", |
62 * "owner" = "uid", | |
62 * }, | 63 * }, |
63 * revision_metadata_keys = { | 64 * revision_metadata_keys = { |
64 * "revision_user" = "revision_uid", | 65 * "revision_user" = "revision_uid", |
65 * "revision_created" = "revision_timestamp", | 66 * "revision_created" = "revision_timestamp", |
66 * "revision_log_message" = "revision_log" | 67 * "revision_log_message" = "revision_log" |
80 * } | 81 * } |
81 * ) | 82 * ) |
82 */ | 83 */ |
83 class Node extends EditorialContentEntityBase implements NodeInterface { | 84 class Node extends EditorialContentEntityBase implements NodeInterface { |
84 | 85 |
86 use EntityOwnerTrait; | |
87 | |
85 /** | 88 /** |
86 * Whether the node is being previewed or not. | 89 * Whether the node is being previewed or not. |
87 * | 90 * |
88 * The variable is set to public as it will give a considerable performance | 91 * The variable is set to public as it will give a considerable performance |
89 * improvement. See https://www.drupal.org/node/2498919. | 92 * improvement. See https://www.drupal.org/node/2498919. |
251 } | 254 } |
252 | 255 |
253 /** | 256 /** |
254 * {@inheritdoc} | 257 * {@inheritdoc} |
255 */ | 258 */ |
256 public function getOwner() { | |
257 return $this->get('uid')->entity; | |
258 } | |
259 | |
260 /** | |
261 * {@inheritdoc} | |
262 */ | |
263 public function getOwnerId() { | |
264 return $this->getEntityKey('uid'); | |
265 } | |
266 | |
267 /** | |
268 * {@inheritdoc} | |
269 */ | |
270 public function setOwnerId($uid) { | |
271 $this->set('uid', $uid); | |
272 return $this; | |
273 } | |
274 | |
275 /** | |
276 * {@inheritdoc} | |
277 */ | |
278 public function setOwner(UserInterface $account) { | |
279 $this->set('uid', $account->id()); | |
280 return $this; | |
281 } | |
282 | |
283 /** | |
284 * {@inheritdoc} | |
285 */ | |
286 public function getRevisionAuthor() { | 259 public function getRevisionAuthor() { |
287 return $this->getRevisionUser(); | 260 return $this->getRevisionUser(); |
288 } | 261 } |
289 | 262 |
290 /** | 263 /** |
298 /** | 271 /** |
299 * {@inheritdoc} | 272 * {@inheritdoc} |
300 */ | 273 */ |
301 public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { | 274 public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { |
302 $fields = parent::baseFieldDefinitions($entity_type); | 275 $fields = parent::baseFieldDefinitions($entity_type); |
276 $fields += static::ownerBaseFieldDefinitions($entity_type); | |
303 | 277 |
304 $fields['title'] = BaseFieldDefinition::create('string') | 278 $fields['title'] = BaseFieldDefinition::create('string') |
305 ->setLabel(t('Title')) | 279 ->setLabel(t('Title')) |
306 ->setRequired(TRUE) | 280 ->setRequired(TRUE) |
307 ->setTranslatable(TRUE) | 281 ->setTranslatable(TRUE) |
316 'type' => 'string_textfield', | 290 'type' => 'string_textfield', |
317 'weight' => -5, | 291 'weight' => -5, |
318 ]) | 292 ]) |
319 ->setDisplayConfigurable('form', TRUE); | 293 ->setDisplayConfigurable('form', TRUE); |
320 | 294 |
321 $fields['uid'] = BaseFieldDefinition::create('entity_reference') | 295 $fields['uid'] |
322 ->setLabel(t('Authored by')) | 296 ->setLabel(t('Authored by')) |
323 ->setDescription(t('The username of the content author.')) | 297 ->setDescription(t('The username of the content author.')) |
324 ->setRevisionable(TRUE) | 298 ->setRevisionable(TRUE) |
325 ->setSetting('target_type', 'user') | |
326 ->setDefaultValueCallback('Drupal\node\Entity\Node::getCurrentUserId') | |
327 ->setTranslatable(TRUE) | |
328 ->setDisplayOptions('view', [ | 299 ->setDisplayOptions('view', [ |
329 'label' => 'hidden', | 300 'label' => 'hidden', |
330 'type' => 'author', | 301 'type' => 'author', |
331 'weight' => 0, | 302 'weight' => 0, |
332 ]) | 303 ]) |
407 /** | 378 /** |
408 * Default value callback for 'uid' base field definition. | 379 * Default value callback for 'uid' base field definition. |
409 * | 380 * |
410 * @see ::baseFieldDefinitions() | 381 * @see ::baseFieldDefinitions() |
411 * | 382 * |
383 * @deprecated The ::getCurrentUserId method is deprecated in 8.6.x and will | |
384 * be removed before 9.0.0. | |
385 * | |
412 * @return array | 386 * @return array |
413 * An array of default values. | 387 * An array of default values. |
414 */ | 388 */ |
415 public static function getCurrentUserId() { | 389 public static function getCurrentUserId() { |
390 @trigger_error('The ::getCurrentUserId method is deprecated in 8.6.x and will be removed before 9.0.0.', E_USER_DEPRECATED); | |
416 return [\Drupal::currentUser()->id()]; | 391 return [\Drupal::currentUser()->id()]; |
417 } | 392 } |
418 | 393 |
419 } | 394 } |