diff --git a/core/modules/workspaces/src/Entity/Workspace.php b/core/modules/workspaces/src/Entity/Workspace.php index 44a7915002fad95a5938fff30d5441c8c74ba40f..5796b207bf03c6d999302bb672998d485443e2b6 100644 --- a/core/modules/workspaces/src/Entity/Workspace.php +++ b/core/modules/workspaces/src/Entity/Workspace.php @@ -8,7 +8,7 @@ use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Field\BaseFieldDefinition; use Drupal\Core\StringTranslation\TranslatableMarkup; -use Drupal\user\UserInterface; +use Drupal\user\EntityOwnerTrait; use Drupal\workspaces\WorkspaceInterface; /** @@ -50,6 +50,7 @@ * "uuid" = "uuid", * "label" = "label", * "uid" = "uid", + * "owner" = "uid", * }, * links = { * "add-form" = "/admin/config/workflow/workspaces/add", @@ -64,12 +65,14 @@ class Workspace extends ContentEntityBase implements WorkspaceInterface { use EntityChangedTrait; + use EntityOwnerTrait; /** * {@inheritdoc} */ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { $fields = parent::baseFieldDefinitions($entity_type); + $fields += static::ownerBaseFieldDefinitions($entity_type); $fields['id'] = BaseFieldDefinition::create('string') ->setLabel(new TranslatableMarkup('Workspace ID')) @@ -87,12 +90,9 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { ->setSetting('max_length', 128) ->setRequired(TRUE); - $fields['uid'] = BaseFieldDefinition::create('entity_reference') + $fields['uid'] ->setLabel(new TranslatableMarkup('Owner')) ->setDescription(new TranslatableMarkup('The workspace owner.')) - ->setRevisionable(TRUE) - ->setSetting('target_type', 'user') - ->setDefaultValueCallback('Drupal\workspaces\Entity\Workspace::getCurrentUserId') ->setDisplayOptions('form', [ 'type' => 'entity_reference_autocomplete', 'weight' => 5, @@ -139,34 +139,6 @@ public function setCreatedTime($created) { return $this->set('created', (int) $created); } - /** - * {@inheritdoc} - */ - public function getOwner() { - return $this->get('uid')->entity; - } - - /** - * {@inheritdoc} - */ - public function setOwner(UserInterface $account) { - return $this->set('uid', $account->id()); - } - - /** - * {@inheritdoc} - */ - public function getOwnerId() { - return $this->get('uid')->target_id; - } - - /** - * {@inheritdoc} - */ - public function setOwnerId($uid) { - return $this->set('uid', $uid); - } - /** * {@inheritdoc} */ @@ -189,12 +161,14 @@ public static function postDelete(EntityStorageInterface $storage, array $entiti /** * Default value callback for 'uid' base field definition. * - * @see ::baseFieldDefinitions() + * @deprecated The ::getCurrentUserId method is deprecated in 8.6.x and will + * be removed before 9.0.0. * * @return int[] * An array containing the ID of the current user. */ public static function getCurrentUserId() { + @trigger_error('The ::getCurrentUserId method is deprecated in 8.6.x and will be removed before 9.0.0.', E_USER_DEPRECATED); return [\Drupal::currentUser()->id()]; }