Unverified Commit 69a3c90c authored by alexpott's avatar alexpott

Issue #2975957 by Sam152, amateescu: Convert the Workspace entity to use EntityOwnerTrait

parent 70fed9cb
......@@ -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()];
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment