WorkableItemWithRevision.php in Drupal PM (Project Management) 4.x
File
modules/pm_project/src/Entity/WorkableItemWithRevision.php
View source
<?php
namespace Drupal\pm_project\Entity;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Entity\RevisionableInterface;
use Drupal\Core\Entity\RevisionLogEntityTrait;
abstract class WorkableItemWithRevision extends WorkableItem implements WorkableItemWithRevisionInterface {
use RevisionLogEntityTrait;
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
$fields = parent::baseFieldDefinitions($entity_type);
$fields += static::revisionLogBaseFieldDefinitions($entity_type);
return $fields;
}
protected function urlRouteParameters($rel) {
$uri_route_parameters = parent::urlRouteParameters($rel);
if ($rel === 'revision_revert' && $this instanceof RevisionableInterface) {
$uri_route_parameters[$this
->getEntityTypeId() . '_revision'] = $this
->getRevisionId();
}
elseif ($rel === 'revision_delete' && $this instanceof RevisionableInterface) {
$uri_route_parameters[$this
->getEntityTypeId() . '_revision'] = $this
->getRevisionId();
}
return $uri_route_parameters;
}
public function preSave(EntityStorageInterface $storage) {
parent::preSave($storage);
if (!$this
->getRevisionUser()) {
$this
->setRevisionUserId($this
->getOwnerId());
}
}
}