From 9dc9150d5f20e8177eb3b23d137d95172f1215f2 Mon Sep 17 00:00:00 2001 From: Daniel Wehner <daniel@tag1consulting.com> Date: Sun, 14 Feb 2016 18:49:10 +0100 Subject: [PATCH] Address feedback from bojanz --- src/EntityRevisionTrait.php | 57 ------------------- src/Form/RevisionRevertForm.php | 8 +-- .../RevisionableContentEntityBase.php | 34 +++++++++++ src/Routing/RevisionRouteProvider.php | 4 +- tests/src/Kernel/RevisionBasicUITest.php | 2 +- 5 files changed, 40 insertions(+), 65 deletions(-) delete mode 100644 src/EntityRevisionTrait.php create mode 100644 src/Revision/RevisionableContentEntityBase.php diff --git a/src/EntityRevisionTrait.php b/src/EntityRevisionTrait.php deleted file mode 100644 index 43bff9d..0000000 --- a/src/EntityRevisionTrait.php +++ /dev/null @@ -1,57 +0,0 @@ -<?php - -/** - * @file - * Contains \Drupal\entity\EntityRevisionTrait. - */ - -namespace Drupal\entity; - -/** - * Provides fixes for revisions - */ -trait EntityRevisionTrait { - - /** - * @return \Drupal\Core\Entity\EntityTypeInterface - */ - abstract protected function getEntityType(); - - /** - * @return string - */ - abstract protected function getEntityTypeId(); - - /** - * @return mixed - */ - abstract protected function getRevisionId(); - - /** - * Gets an array of placeholders for this entity. - * - * Individual entity classes may override this method to add additional - * placeholders if desired. If so, they should be sure to replicate the - * property caching logic. - * - * @param string $rel - * The link relationship type, for example: canonical or edit-form. - * - * @return array - * An array of URI placeholders. - */ - protected function urlRouteParametersWithRevisionSupport($rel) { - $uri_route_parameters = []; - - if ($rel != 'collection') { - // The entity ID is needed as a route parameter. - $uri_route_parameters[$this->getEntityTypeId()] = $this->id(); - } - if (strpos($this->getEntityType()->getLinkTemplate($rel), $this->getEntityTypeId() . '_revision') !== FALSE) { - $uri_route_parameters[$this->getEntityTypeId() . '_revision'] = $this->getRevisionId(); - } - - return $uri_route_parameters; - } - -} diff --git a/src/Form/RevisionRevertForm.php b/src/Form/RevisionRevertForm.php index 6342365..6544cc8 100644 --- a/src/Form/RevisionRevertForm.php +++ b/src/Form/RevisionRevertForm.php @@ -19,7 +19,7 @@ use Symfony\Component\HttpFoundation\Request; class RevisionRevertForm extends ConfirmFormBase { /** - * The node revision. + * The entity revision. * * @var \Drupal\Core\Entity\EntityInterface|\Drupal\Core\Entity\RevisionableInterface|\Drupal\entity\Revision\EntityRevisionLogInterface */ @@ -124,9 +124,7 @@ class RevisionRevertForm extends ConfirmFormBase { if ($this->revision instanceof EntityRevisionLogInterface) { $original_revision_timestamp = $this->revision->getRevisionCreationTime(); - if ($this->revision instanceof EntityRevisionLogInterface) { - $this->revision->setRevisionLogMessage($this->t('Copy of the revision from %date.', ['%date' => $this->dateFormatter->format($original_revision_timestamp)])); - } + $this->revision->setRevisionLogMessage($this->t('Copy of the revision from %date.', ['%date' => $this->dateFormatter->format($original_revision_timestamp)])); drupal_set_message(t('@type %title has been reverted to the revision from %revision-date.', ['@type' => $this->getBundleLabel($this->revision), '%title' => $this->revision->label(), '%revision-date' => $this->dateFormatter->format($original_revision_timestamp)])); } else { @@ -138,7 +136,7 @@ class RevisionRevertForm extends ConfirmFormBase { $this->logger('content')->notice('@type: reverted %title revision %revision.', ['@type' => $this->revision->bundle(), '%title' => $this->revision->label(), '%revision' => $this->revision->getRevisionId()]); $form_state->setRedirect( "entity.{$this->revision->getEntityTypeId()}.version_history", - array($this->revision->getEntityTypeId() => $this->revision->id()) + [$this->revision->getEntityTypeId() => $this->revision->id()] ); } diff --git a/src/Revision/RevisionableContentEntityBase.php b/src/Revision/RevisionableContentEntityBase.php new file mode 100644 index 0000000..2b6ae62 --- /dev/null +++ b/src/Revision/RevisionableContentEntityBase.php @@ -0,0 +1,34 @@ +<?php + +/** + * @file + * Contains \Drupal\entity\Revision\RevisionableContentEntityBase. + */ + +namespace Drupal\entity\Revision; + +use Drupal\Core\Entity\ContentEntityBase; + +/** + * Provides an entity class with revisions. + */ +abstract class RevisionableContentEntityBase extends ContentEntityBase { + + /** + * {@inheritdoc} + */ + protected function urlRouteParameters($rel) { + $uri_route_parameters = []; + + if ($rel != 'collection') { + // The entity ID is needed as a route parameter. + $uri_route_parameters[$this->getEntityTypeId()] = $this->id(); + } + if (strpos($this->getEntityType()->getLinkTemplate($rel), $this->getEntityTypeId() . '_revision') !== FALSE) { + $uri_route_parameters[$this->getEntityTypeId() . '_revision'] = $this->getRevisionId(); + } + + return $uri_route_parameters; + } + +} diff --git a/src/Routing/RevisionRouteProvider.php b/src/Routing/RevisionRouteProvider.php index 47d551d..d539c61 100644 --- a/src/Routing/RevisionRouteProvider.php +++ b/src/Routing/RevisionRouteProvider.php @@ -26,7 +26,7 @@ class RevisionRouteProvider implements EntityRouteProviderInterface { if ($view_route = $this->getRevisionViewRoute($entity_type)) { $collection->add("entity.$entity_type_id.revision", $view_route); } - if ($view_route = $this->getRevisionrevertRoute($entity_type)) { + if ($view_route = $this->getRevisionRevertRoute($entity_type)) { $collection->add("entity.$entity_type_id.revision_revert_form", $view_route); } @@ -74,7 +74,7 @@ class RevisionRouteProvider implements EntityRouteProviderInterface { * @return \Symfony\Component\Routing\Route|null * The generated route, if available. */ - protected function getRevisionrevertRoute(EntityTypeInterface $entity_type) { + protected function getRevisionRevertRoute(EntityTypeInterface $entity_type) { if ($entity_type->hasLinkTemplate('revision-revert-form')) { $entity_type_id = $entity_type->id(); $route = new Route($entity_type->getLinkTemplate('revision-revert-form')); diff --git a/tests/src/Kernel/RevisionBasicUITest.php b/tests/src/Kernel/RevisionBasicUITest.php index e4a3c4c..2b15cfb 100644 --- a/tests/src/Kernel/RevisionBasicUITest.php +++ b/tests/src/Kernel/RevisionBasicUITest.php @@ -43,7 +43,7 @@ class RevisionBasicUITest extends KernelTestBase { \Drupal::service('router.builder')->rebuild(); } - public function ptestRevisionView() { + public function testRevisionView() { $entity = EnhancedEntity::create([ 'name' => 'rev 1', 'type' => 'default', -- GitLab