summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Pott2018-09-18 12:48:47 (GMT)
committerAlex Pott2018-09-18 12:48:53 (GMT)
commit1564d992346c8524f9e7573b763eeb2e3dc0d180 (patch)
treef66ad045b2a401688110ff9c6f13732b266422c0
parent21f727eae070990cea3d996393177bfd33d1b8bd (diff)
Issue #2975957 by Sam152, amateescu: Convert the Workspace entity to use EntityOwnerTrait
(cherry picked from commit 69a3c90ce9154818b140ecd7d041d586c2f93881)
-rw-r--r--core/modules/workspaces/src/Entity/Workspace.php42
1 files changed, 8 insertions, 34 deletions
diff --git a/core/modules/workspaces/src/Entity/Workspace.php b/core/modules/workspaces/src/Entity/Workspace.php
index 44a7915..5796b20 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\EntityStorageInterface;
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 @@ use Drupal\workspaces\WorkspaceInterface;
* "uuid" = "uuid",
* "label" = "label",
* "uid" = "uid",
+ * "owner" = "uid",
* },
* links = {
* "add-form" = "/admin/config/workflow/workspaces/add",
@@ -64,12 +65,14 @@ use Drupal\workspaces\WorkspaceInterface;
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 @@ class Workspace extends ContentEntityBase implements WorkspaceInterface {
->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,
@@ -142,34 +142,6 @@ class Workspace extends ContentEntityBase implements WorkspaceInterface {
/**
* {@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}
- */
public static function postDelete(EntityStorageInterface $storage, array $entities) {
parent::postDelete($storage, $entities);
@@ -189,12 +161,14 @@ class Workspace extends ContentEntityBase implements WorkspaceInterface {
/**
* 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()];
}