Now that #2634212: Offer a diff controller for all entity types leveraging entity API module has landed, we have 2 controllers, which are almost identical.

#2752725: Turn EntityComparisonBase into a service moves 50% of the original controller logic into a service, but still leaves the other 50% in the controllers.

Either NodeRevisionController should be removed, and the routing changed so that only GenericRevisionController is used, or if we need 2 controllers then the duplicate logic should to be moved to EntityComparisonBase.

We tried to remove it, but ran into permissions issues in the resulting routing, so it's not a completely trivial issue.

Priority Major because it complicates development efforts having to keep 2 near-identical controllers in sync.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jonathanjfshaw created an issue. See original summary.

jonathanshaw’s picture

Issue summary: View changes
jonathanshaw’s picture

The simplest possible fix would seem to be:

a) change "\Drupal\diff\Controller\NodeRevisionController::compareNodeRevisions" to \Drupal\diff\Controller\GenericRevisionController::compareEntityRevisions in the diff.routing.yml and DiffRouteProvider.php

b) move the revisionOverview function across from nodeRevisionController.php to genericRevisionController.php and change routeSubscriber.php to point to new location

However, just making the first change in diff.routing.yml leads to a permission denied issue when trying to view a node diff.

johnchque’s picture

Assigned: Unassigned » johnchque
jonathanshaw’s picture

Glad you're working on this @yongt9412, it's beyond me. When you've done it, I'll reroll #2752725: Turn EntityComparisonBase into a service on top of it.

johnchque’s picture

Status: Active » Needs review
FileSize
11.14 KB

Thanks @jonathanjfshaw.
This is an early patch, not really sure if we can have security problems here. But it works as far as I tested.

Status: Needs review » Needs work

The last submitted patch, 6: remove_redundant-2759627-6.patch, failed testing.

Berdir’s picture

+++ b/src/Controller/NodeRevisionController.php
@@ -45,264 +45,28 @@ class NodeRevisionController extends EntityComparisonBase {
       'title' => $this->t('Standard'),
-      'url' => Url::fromRoute('diff.revisions_diff', array(
-        'node' => $nid,
+      'url' => Url::fromRoute('entity.node.revisions_diff', array(
+        'node' => $entity->id(),
         'left_vid' => $left_vid,
         'right_vid' => $right_vid,
       )),
     );
     $links['raw_plain'] = array(
       'title' => $this->t('Markdown'),
-      'url' => Url::fromRoute('diff.revisions_diff', array(
-        'node' => $nid,
+      'url' => Url::fromRoute('entity.node.revisions_diff', array(
+        'node' => $entity->id(),

+++ b/src/Form/RevisionOverviewForm.php
@@ -343,7 +343,7 @@ class RevisionOverviewForm extends FormBase {
     $redirect_url = Url::fromRoute(
-      'diff.revisions_diff',
+      'entity.node.revisions_diff',
       array(

I don't think those changes are correct, we still use our route now?

johnchque’s picture

+++ b/diff.routing.yml
@@ -1,4 +1,4 @@
-diff.revisions_diff:
+entity.node.revisions_diff:

actually yes, just changed it to make it fit. Should I keep it as it was?

johnchque’s picture

Status: Needs work » Needs review
FileSize
15.03 KB

Ok, let's start again, tried something different. seems to work.

Status: Needs review » Needs work

The last submitted patch, 10: remove_redundant-2759627-10.patch, failed testing.

johnchque’s picture

Status: Needs work » Needs review
FileSize
1.35 KB
16.38 KB

This should fix the tests. :)

Berdir’s picture

  1. +++ b/diff.routing.yml
    @@ -1,5 +1,5 @@
     diff.revisions_diff:
    -  path: '/node/{node}/revisions/view/{left_vid}/{right_vid}/{filter}'
    +  path: '/node/{node}/revisions/view/{left_revision}/{right_revision}/{filter}'
    

    hm, why change the slug names? We want to get rid of this eventually completely but until then, I'd try to keep the changes as minimal as possible.

  2. +++ b/src/Controller/GenericRevisionController.php
    @@ -210,8 +210,9 @@ class GenericRevisionController extends EntityComparisonBase {
             );
             $revision_date = $this->date->format($revision->getRevisionCreationTime(), 'short');
    +        $url = $entity_type_id != 'node' ? "entity.$entity_type_id.revisions_diff": 'entity.node.revision';
             $revision_link = $this->t($revision_log . '@date', array(
    

    ah, I see why you tried to rename...

    but this is not a url, it is a route name.

johnchque’s picture

Added diff route function. Just not really sure if the diff_route function should avoid changing the variables on the route for leaving it as left_vid and right_vid?

Status: Needs review » Needs work

The last submitted patch, 14: remove_redundant-2759627-14.patch, failed testing.

johnchque’s picture

Strange, it passes locally.

johnchque’s picture

Status: Needs work » Needs review
Berdir’s picture

+++ b/src/Controller/GenericRevisionController.php
@@ -210,9 +210,9 @@ class GenericRevisionController extends EntityComparisonBase {
-        $url = $entity_type_id != 'node' ? "entity.$entity_type_id.revisions_diff": 'entity.node.revision';
+        $route_name = $entity_type_id != 'node' ? "entity.$entity_type_id.revisions_diff": 'entity.node.revision';
         $revision_link = $this->t($revision_log . '@date', array(
-            '@date' => $this->l($revision_date, Url::fromRoute($url, array(
+            '@date' => $this->l($revision_date, Url::fromRoute($route_name, array(
               $entity_type_id => $revision->id(),

you should be able to replace this one now too?

Looks like all the calls are on this controller, so maybe better to make a non-tatic method here?

johnchque’s picture

Refactored more code. Moved the function. :D

johnchque’s picture

Better now probably?

Berdir’s picture

Status: Needs review » Needs work
+++ b/src/Controller/GenericRevisionController.php
@@ -351,4 +327,39 @@ class GenericRevisionController extends EntityComparisonBase {
+   * @param boolean $raw_plain
+   *   Flag to determinate if the route should add a raw_plain filter.
...
+  protected function diffRoute(EntityInterface $entity, $left_vid, $right_vid, $raw_plain = FALSE) {

boolean seems to restricting.

Just add $filter as argument, NULL by default, if set, add it to the parameters.

johnchque’s picture

Status: Needs work » Needs review
FileSize
18.09 KB
1.05 KB

Changes made.

Status: Needs review » Needs work

The last submitted patch, 22: remove_redundant-2759627-22.patch, failed testing.

johnchque’s picture

Status: Needs work » Needs review
johnchque’s picture

I was blind! This should work better!

Berdir’s picture

Status: Needs review » Reviewed & tested by the community

I think this looks good now.

miro_dietiker’s picture

Status: Reviewed & tested by the community » Fixed

Yay, committed. :-)

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.