Skip to content
Snippets Groups Projects
Commit d6d58f15 authored by fago's avatar fago
Browse files

Fix EntityRevisionLogTrait user getter and setters to have ID and entity variations.

parent e3164af6
No related branches found
No related tags found
No related merge requests found
...@@ -43,12 +43,30 @@ interface EntityRevisionLogInterface { ...@@ -43,12 +43,30 @@ interface EntityRevisionLogInterface {
/** /**
* Sets the entity revision author. * Sets the entity revision author.
* *
* @param \Drupal\user\UserInterface $account
* The user account of the revision author.
*
* @return $this
*/
public function setRevisionUser($account);
/**
* Gets the entity revision author ID.
*
* @return int
* The user ID.
*/
public function getRevisionUserId();
/**
* Sets the entity revision author by ID.
*
* @param int $user_id * @param int $user_id
* The user ID of the revision author. * The user ID of the revision author.
* *
* @return $this * @return $this
*/ */
public function setRevisionUser($user_id); public function setRevisionUserId($user_id);
/** /**
* Returns the entity revision log message. * Returns the entity revision log message.
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
namespace Drupal\entity\Revision; namespace Drupal\entity\Revision;
use Drupal\Core\Field\BaseFieldDefinition; use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\user\UserInterface;
/** /**
* Provides a trait implementing \Drupal\entity\Revision\EntityRevisionLogInterface. * Provides a trait implementing \Drupal\entity\Revision\EntityRevisionLogInterface.
...@@ -74,7 +75,22 @@ trait EntityRevisionLogTrait { ...@@ -74,7 +75,22 @@ trait EntityRevisionLogTrait {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function setRevisionUser($user_id) { public function setRevisionUser(UserInterface $account) {
$this->revision_user->entity = $account;
return $this;
}
/**
* {@inheritdoc}
*/
public function getRevisionUserId() {
return $this->revision_user->target_id;
}
/**
* {@inheritdoc}
*/
public function setRevisionUserId($user_id) {
$this->revision_user->target_id = $user_id; $this->revision_user->target_id = $user_id;
return $this; return $this;
} }
......
...@@ -54,8 +54,12 @@ class EntityRevisionLogTraitTest extends KernelTestBase { ...@@ -54,8 +54,12 @@ class EntityRevisionLogTraitTest extends KernelTestBase {
$entity->setRevisionCreationTime(1234567890); $entity->setRevisionCreationTime(1234567890);
$this->assertEquals(1234567890, $entity->getRevisionCreationTime()); $this->assertEquals(1234567890, $entity->getRevisionCreationTime());
$entity->setRevisionUser($user2->id()); $entity->setRevisionUser($user2);
$this->assertEquals($user2->id(), $entity->getRevisionUser()->id()); $this->assertEquals($user2->id(), $entity->getRevisionUser()->id());
$this->assertEquals($user2->id(), $entity->getRevisionUserId());
$entity->setRevisionUserId($user->id());
$this->assertEquals($user->id(), $entity->getRevisionUserId());
$entity->setRevisionLogMessage('Giraffe!'); $entity->setRevisionLogMessage('Giraffe!');
$this->assertEquals('Giraffe!', $entity->getRevisionLogMessage()); $this->assertEquals('Giraffe!', $entity->getRevisionLogMessage());
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment