Unverified Commit 5d37cffd authored by alexpott's avatar alexpott

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

This reverts commit 1564d992.
parent bc6b09fc
......@@ -8,7 +8,7 @@
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\user\EntityOwnerTrait;
use Drupal\user\UserInterface;
use Drupal\workspaces\WorkspaceInterface;
/**
......@@ -50,7 +50,6 @@
* "uuid" = "uuid",
* "label" = "label",
* "uid" = "uid",
* "owner" = "uid",
* },
* links = {
* "add-form" = "/admin/config/workflow/workspaces/add",
......@@ -65,14 +64,12 @@
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'))
......@@ -90,9 +87,12 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
->setSetting('max_length', 128)
->setRequired(TRUE);
$fields['uid']
$fields['uid'] = BaseFieldDefinition::create('entity_reference')
->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,6 +139,34 @@ 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}
*/
......@@ -161,14 +189,12 @@ public static function postDelete(EntityStorageInterface $storage, array $entiti
/**
* Default value callback for 'uid' base field definition.
*
* @deprecated The ::getCurrentUserId method is deprecated in 8.6.x and will
* be removed before 9.0.0.
* @see ::baseFieldDefinitions()
*
* @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