diff --git a/core/lib/Drupal/Core/Entity/EntityAuthorInterface.php b/core/lib/Drupal/Core/Entity/EntityAuthorInterface.php new file mode 100644 index 0000000..050640d --- /dev/null +++ b/core/lib/Drupal/Core/Entity/EntityAuthorInterface.php @@ -0,0 +1,42 @@ +getFilename(), $file->getOwner()->name) !== 0) { + if (strpos($file->getFilename(), $file->getAuthor()->name) !== 0) { $old_filename = $file->getFilename(); - $file->setFilename($file->getOwner()->name . '_' . $file->getFilename()); + $file->setFilename($file->getAuthor()->name . '_' . $file->getFilename()); $file->save(); watchdog('file', t('%source has been renamed to %destination', array('%source' => $old_filename, '%destination' => $file->getFilename()))); @@ -134,8 +134,8 @@ function hook_file_update(Drupal\file\FileInterface $file) { */ function hook_file_copy(Drupal\file\FileInterface $file, Drupal\file\FileInterface $source) { // Make sure that the file name starts with the owner's user name. - if (strpos($file->getFilename(), $file->getOwner()->name) !== 0) { - $file->setFilename($file->getOwner()->name . '_' . $file->getFilename()); + if (strpos($file->getFilename(), $file->getAuthor()->name) !== 0) { + $file->setFilename($file->getAuthor()->name . '_' . $file->getFilename()); $file->save(); watchdog('file', t('Copied file %source has been renamed to %destination', array('%source' => $source->filename, '%destination' => $file->getFilename()))); @@ -154,8 +154,8 @@ function hook_file_copy(Drupal\file\FileInterface $file, Drupal\file\FileInterfa */ function hook_file_move(Drupal\file\FileInterface $file, Drupal\file\FileInterface $source) { // Make sure that the file name starts with the owner's user name. - if (strpos($file->getFilename(), $file->getOwner()->name) !== 0) { - $file->setFilename($file->getOwner()->name . '_' . $file->getFilename()); + if (strpos($file->getFilename(), $file->getAuthor()->name) !== 0) { + $file->setFilename($file->getAuthor()->name . '_' . $file->getFilename()); $file->save(); watchdog('file', t('Moved file %source has been renamed to %destination', array('%source' => $source->filename, '%destination' => $file->getFilename()))); diff --git a/core/modules/file/file.module b/core/modules/file/file.module index e59126d..0bb97f8 100644 --- a/core/modules/file/file.module +++ b/core/modules/file/file.module @@ -633,7 +633,7 @@ function file_file_download($uri, $field_type = 'file') { // temporary files where the host entity has not yet been saved (for example, // an image preview on a node/add form) in which case, allow download by the // file's owner. - if (empty($references) && ($file->isPermanent() || $file->getOwner()->id() != $user->id())) { + if (empty($references) && ($file->isPermanent() || $file->getAuthorId() != $user->id())) { return; } @@ -1047,7 +1047,7 @@ function file_tokens($type, $tokens, array $data = array(), array $options = arr break; case 'owner': - $name = $file->getOwner()->label(); + $name = $file->getAuthor()->label(); $replacements[$original] = $sanitize ? check_plain($name) : $name; break; } @@ -1057,8 +1057,8 @@ function file_tokens($type, $tokens, array $data = array(), array $options = arr $replacements += $token_service->generate('date', $date_tokens, array('date' => $file->getChangedTime()), $options); } - if (($owner_tokens = $token_service->findWithPrefix($tokens, 'owner')) && $file->getOwner()) { - $replacements += $token_service->generate('user', $owner_tokens, array('user' => $file->getOwner()), $options); + if (($owner_tokens = $token_service->findWithPrefix($tokens, 'owner')) && $file->getAuthor()) { + $replacements += $token_service->generate('user', $owner_tokens, array('user' => $file->getAuthor()), $options); } } diff --git a/core/modules/file/lib/Drupal/file/Entity/File.php b/core/modules/file/lib/Drupal/file/Entity/File.php index 833f2db..b632007 100644 --- a/core/modules/file/lib/Drupal/file/Entity/File.php +++ b/core/modules/file/lib/Drupal/file/Entity/File.php @@ -120,15 +120,23 @@ public function getChangedTime() { /** * {@inheritdoc} */ - public function getOwner() { + public function getAuthor() { return $this->get('uid')->entity; } /** * {@inheritdoc} */ - public function setOwner(UserInterface $user) { - return $this->get('uid')->entity = $user; + public function getAuthorId() { + return $this->get('uid')->value; + } + + /** + * {@inheritdoc} + */ + public function setAuthorId($uid) { + $this->set('uid', $uid); + return $this; } /** diff --git a/core/modules/file/lib/Drupal/file/FileInterface.php b/core/modules/file/lib/Drupal/file/FileInterface.php index 73783ef..31f7350 100644 --- a/core/modules/file/lib/Drupal/file/FileInterface.php +++ b/core/modules/file/lib/Drupal/file/FileInterface.php @@ -8,13 +8,14 @@ namespace Drupal\file; use Drupal\Core\Entity\ContentEntityInterface; +use Drupal\Core\Entity\EntityAuthorInterface; use Drupal\Core\Entity\EntityChangedInterface; use Drupal\user\UserInterface; /** * Defines getter and setter methods for file entity base fields. */ -interface FileInterface extends ContentEntityInterface, EntityChangedInterface { +interface FileInterface extends ContentEntityInterface, EntityChangedInterface, EntityAuthorInterface { /** * Returns the name of the file. @@ -111,20 +112,4 @@ public function setPermanent(); */ public function setTemporary(); - /** - * Returns the user that owns this file. - * - * @return \Drupal\user\UserInterface - * The user that owns the file. - */ - public function getOwner(); - - /** - * Sets the user that owns this file. - * - * @param \Drupal\user\UserInterface $user - * The user that owns the file. - */ - public function setOwner(UserInterface $user); - } diff --git a/core/modules/file/lib/Drupal/file/Tests/FileTokenReplaceTest.php b/core/modules/file/lib/Drupal/file/Tests/FileTokenReplaceTest.php index ec1950c..d5f7e39 100644 --- a/core/modules/file/lib/Drupal/file/Tests/FileTokenReplaceTest.php +++ b/core/modules/file/lib/Drupal/file/Tests/FileTokenReplaceTest.php @@ -56,7 +56,7 @@ function testFileTokenReplacement() { $tests['[file:timestamp]'] = format_date($file->getChangedTime(), 'medium', '', NULL, $language_interface->id); $tests['[file:timestamp:short]'] = format_date($file->getChangedTime(), 'short', '', NULL, $language_interface->id); $tests['[file:owner]'] = check_plain(user_format_name($this->admin_user)); - $tests['[file:owner:uid]'] = $file->getOwner()->id(); + $tests['[file:owner:uid]'] = $file->getAuthorId(); // Test to make sure that we generated something for each token. $this->assertFalse(in_array(0, array_map('strlen', $tests)), 'No empty tokens generated.'); diff --git a/core/modules/node/lib/Drupal/node/NodeInterface.php b/core/modules/node/lib/Drupal/node/NodeInterface.php index 12d334b..bdb54cb 100644 --- a/core/modules/node/lib/Drupal/node/NodeInterface.php +++ b/core/modules/node/lib/Drupal/node/NodeInterface.php @@ -7,6 +7,7 @@ namespace Drupal\node; +use Drupal\Core\Entity\EntityAuthorInterface; use Drupal\Core\Entity\EntityChangedInterface; use Drupal\Core\Entity\ContentEntityInterface; use Drupal\user\UserInterface; @@ -14,7 +15,7 @@ /** * Provides an interface defining a node entity. */ -interface NodeInterface extends ContentEntityInterface, EntityChangedInterface { +interface NodeInterface extends ContentEntityInterface, EntityChangedInterface, EntityAuthorInterface { /** * Returns the node type. @@ -25,7 +26,6 @@ public function getType(); /** - * * Returns the node title. * * @return string @@ -102,33 +102,6 @@ public function isSticky(); public function setSticky($sticky); /** - * Returns the node author user entity. - * - * @return \Drupal\user\UserInterface - * The author user entity. - */ - public function getAuthor(); - - /** - * Returns the node author user ID. - * - * @return int - * The author user ID. - */ - public function getAuthorId(); - - /** - * Sets the node author user ID. - * - * @param int $uid - * The author user id. - * - * @return \Drupal\node\NodeInterface - * The called node entity. - */ - public function setAuthorId($uid); - - /** * Returns the node published status indicator. * * Unpublished nodes are only visible to their authors and to administrators. @@ -160,7 +133,7 @@ public function getRevisionCreationTime(); /** * Sets the node revision creation timestamp. * - * @param int $imestamp + * @param int $timestamp * The UNIX timestamp of when this revision was created. * * @return \Drupal\node\NodeInterface diff --git a/core/modules/system/lib/Drupal/system/Tests/File/FileTestBase.php b/core/modules/system/lib/Drupal/system/Tests/File/FileTestBase.php index 540c19a..221c547 100644 --- a/core/modules/system/lib/Drupal/system/Tests/File/FileTestBase.php +++ b/core/modules/system/lib/Drupal/system/Tests/File/FileTestBase.php @@ -37,7 +37,7 @@ function setUp() { */ function assertFileUnchanged(FileInterface $before, FileInterface $after) { $this->assertEqual($before->id(), $after->id(), t('File id is the same: %file1 == %file2.', array('%file1' => $before->id(), '%file2' => $after->id())), 'File unchanged'); - $this->assertEqual($before->getOwner()->id(), $after->getOwner()->id(), t('File owner is the same: %file1 == %file2.', array('%file1' => $before->getOwner()->id(), '%file2' => $after->getOwner()->id())), 'File unchanged'); + $this->assertEqual($before->getAuthorId(), $after->getAuthorId(), t('File owner is the same: %file1 == %file2.', array('%file1' => $before->getAuthorId(), '%file2' => $after->getAuthorId())), 'File unchanged'); $this->assertEqual($before->getFilename(), $after->getFilename(), t('File name is the same: %file1 == %file2.', array('%file1' => $before->getFilename(), '%file2' => $after->getFilename())), 'File unchanged'); $this->assertEqual($before->getFileUri(), $after->getFileUri(), t('File path is the same: %file1 == %file2.', array('%file1' => $before->getFileUri(), '%file2' => $after->getFileUri())), 'File unchanged'); $this->assertEqual($before->getMimeType(), $after->getMimeType(), t('File MIME type is the same: %file1 == %file2.', array('%file1' => $before->getMimeType(), '%file2' => $after->getMimeType())), 'File unchanged');