diff --git a/core/modules/comment/lib/Drupal/comment/Entity/Comment.php b/core/modules/comment/lib/Drupal/comment/Entity/Comment.php index 82055ec..98675be 100644 --- a/core/modules/comment/lib/Drupal/comment/Entity/Comment.php +++ b/core/modules/comment/lib/Drupal/comment/Entity/Comment.php @@ -13,6 +13,7 @@ use Drupal\comment\CommentInterface; use Drupal\Core\Entity\EntityStorageControllerInterface; use Drupal\Core\Language\Language; +use Drupal\user\UserInterface; /** * Defines the comment entity class. @@ -493,4 +494,12 @@ public function setAuthorId($uid) { return $this; } + /** + * {@inheritdoc} + */ + public function setAuthor(UserInterface $account) { + $this->set('uid', $account->id()); + return $this; + } + } diff --git a/core/modules/file/lib/Drupal/file/Entity/File.php b/core/modules/file/lib/Drupal/file/Entity/File.php index 9bbcacb..bab7e74 100644 --- a/core/modules/file/lib/Drupal/file/Entity/File.php +++ b/core/modules/file/lib/Drupal/file/Entity/File.php @@ -141,6 +141,14 @@ public function setAuthorId($uid) { /** * {@inheritdoc} */ + public function setAuthor(UserInterface $account) { + $this->set('uid', $account->id()); + return $this; + } + + /** + * {@inheritdoc} + */ public function isPermanent() { return $this->get('status')->value == FILE_STATUS_PERMANENT; } diff --git a/core/modules/node/lib/Drupal/node/Entity/Node.php b/core/modules/node/lib/Drupal/node/Entity/Node.php index 3700499..7147cd7 100644 --- a/core/modules/node/lib/Drupal/node/Entity/Node.php +++ b/core/modules/node/lib/Drupal/node/Entity/Node.php @@ -12,6 +12,7 @@ use Drupal\Core\Language\Language; use Drupal\Core\Session\AccountInterface; use Drupal\node\NodeInterface; +use Drupal\user\UserInterface; /** * Defines the node entity class. @@ -296,6 +297,14 @@ public function setAuthorId($uid) { /** * {@inheritdoc} */ + public function setAuthor(UserInterface $account) { + $this->set('uid', $account->id()); + return $this; + } + + /** + * {@inheritdoc} + */ public function getRevisionCreationTime() { return $this->get('revision_timestamp')->value; } diff --git a/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Entity/EntityTest.php b/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Entity/EntityTest.php index 25cf73e..e0d5967 100644 --- a/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Entity/EntityTest.php +++ b/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Entity/EntityTest.php @@ -12,6 +12,7 @@ use Drupal\Core\Annotation\Translation; use Drupal\user\EntityAuthorInterface; use Drupal\Core\Language\Language; +use Drupal\user\UserInterface; /** * Defines the test entity class. @@ -179,4 +180,12 @@ public function setAuthorId($uid) { return $this; } + /** + * {@inheritdoc} + */ + public function setAuthor(UserInterface $account) { + $this->set('uid', $account->id()); + return $this; + } + } diff --git a/core/modules/user/lib/Drupal/user/EntityAuthorInterface.php b/core/modules/user/lib/Drupal/user/EntityAuthorInterface.php index cd7f4d8..63a00f3 100644 --- a/core/modules/user/lib/Drupal/user/EntityAuthorInterface.php +++ b/core/modules/user/lib/Drupal/user/EntityAuthorInterface.php @@ -21,6 +21,17 @@ public function getAuthor(); /** + * Returns the entity author's user entity. + * + * @param \Drupal\user\UserInterface $account + * The author user entity. + * + * @return self + * The called entity. + */ + public function setAuthor(UserInterface $account); + + /** * Returns the entity author's user ID. * * @return int