Skip to content
Snippets Groups Projects
Commit ca4941f3 authored by Daniel Wehner's avatar Daniel Wehner
Browse files

address feedback

parent e2ac92bb
No related branches found
No related tags found
No related merge requests found
......@@ -2,10 +2,10 @@
/**
* @file
* Contains \Drupal\src\EnhancedEntityRevisionInterface.
* Contains \Drupal\entity\Revision\EnhancedEntityRevisionInterface.
*/
namespace Drupal\src;
namespace Drupal\entity\Revision;
/**
* Defines an entity type with create/author/log information for revisions.
......
......@@ -2,28 +2,44 @@
/**
* @file
* Contains \Drupal\src\EnhancedEntityRevisionTrait.
* Contains \Drupal\entity\Revision\EnhancedEntityRevisionTrait.
*/
namespace Drupal\src;
namespace Drupal\entity\Revision;
use Drupal\user\Entity\User;
/**
* Provides a trait implementing \Drupal\entity\EnhanceredEntityRevisionInterface.
*/
trait EnhancedEntityRevisionTrait {
/**
* Returns whether the entity type has a specific field.
*
* @param string $field_name
* The field name.
*
* @return bool
*/
abstract function hasField($field_name);
/**
* {@inheritdoc}
*/
public function getRevisionCreationTime() {
return $this->revision_create->value;
if ($this->hasField('revision_create')) {
return $this->revision_create->value;
}
return 0;
}
/**
* {@inheritdoc}
*/
public function setRevisionCreationTime($timestamp) {
$this->revision_create->value = $timestamp;
if ($this->hasField('revision_create')) {
$this->revision_create->value = $timestamp;
}
return $this;
}
......@@ -31,14 +47,19 @@ trait EnhancedEntityRevisionTrait {
* {@inheritdoc}
*/
public function getRevisionAuthor() {
return $this->revision_author->entity;
if ($this->hasField('revision_author')) {
return $this->revision_author->entity;
}
return User::getAnonymousUser();
}
/**
* {@inheritdoc}
*/
public function setRevisionAuthorId($uid) {
$this->revision_author->target_id = $uid;
if ($this->hasField('revision_author')) {
$this->revision_author->target_id = $uid;
}
return $this;
}
......@@ -46,14 +67,19 @@ trait EnhancedEntityRevisionTrait {
* {@inheritdoc}
*/
public function getRevisionLog() {
return $this->revision_log->value;
if ($this->hasField('revision_log')) {
return $this->revision_log->value;
}
return '';
}
/**
* {@inheritdoc}
*/
public function setRevisionLog($revision_log) {
$this->revision_log->value = $revision_log;
if ($this->hasField('revision_log')) {
$this->revision_log->value = $revision_log;
}
return $this;
}
......
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