Problem/Motivation

ContentTranslationRouteSubscriber sets the _admin_route option for translation routes based on the respective edit route's setting. However, it sets _admin_route to FALSE even if the edit route does not specify _admin_route at all. This is not only sloppy but opens the door to a very subtle bug: If a route subscriber runs after ContentTranslationRouteSubscriber it thinks that the translation routes have explicitly disabled _admin_route (like the block demo page does), even though they haven't.

Proposed resolution

Make ContentTranslationRouteSubscriber precisely reproduce the _admin_route option of the edit route, i.e. if it is not set, do not set it either.

Remaining tasks

Is this change still needed?

User interface changes

None.

API changes

Only the priority of ContentTranslationRouteSubscriber is changed, so only modules interacting specifically with content translation routes (I don't know any) will notice this. And since it is only moved earlier in the chain even those module won't break in the majority of cases.
On the other hand for modules interacting with the _admin_route option this might fix a very edge-case-y bug, they probably didn't they had. :-)

Beta phase evaluation

Reference: https://www.drupal.org/core/beta-changes
Issue category Bug because _admin_route is not set correctly
Issue priority Normal
Unfrozen changes Not unfrozen
Prioritized changes Prioritized because it is a bug fix
Disruption This is technically speaking an API change but the actual disruption is zero or very, very close to it
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

tstoeckler’s picture

Status: Active » Needs review
FileSize
4.67 KB

Here we go.

dawehner’s picture

+++ b/core/modules/content_translation/src/Routing/ContentTranslationRouteSubscriber.php
@@ -176,9 +188,14 @@ protected function alterRoutes(RouteCollection $collection) {
-    $events[RoutingEvents::ALTER] = array('onAlterRoutes', -210);
+    // This event subscriber should run after
+    // \Drupal\node\EventSubscriber\NodeAdminRouteSubscriber, which has the
+    // default priority of 0, so the node translation routes can inherit the
+    // _admin_route option from the node edit route. It should run before
+    // \Drupal\system\EventSubscriber\AdminRouteSubscriber, which has a weight
+    // of -200 so that _admin_route can be set automatically for translation
+    // routes under /admin (unless _admin_route has explicitly been disabled).
+    $events[RoutingEvents::ALTER] = array('onAlterRoutes', -50);
     return $events;

This is a much better solution for the problem.

Can we come up with some test coverage for some specific examples?

Status: Needs review » Needs work

The last submitted patch, 1: 2415205-1.patch, failed testing.

tstoeckler’s picture

Status: Needs work » Needs review
FileSize
861 bytes
4.7 KB

Here we go.

The problem was that $admin_route was being conditionally set in a foreach-loop but never being reset.

tstoeckler’s picture

Regarding test coverage: We implicitly test both !$route->hasOption('_admin_route') (CommentTranslationUITest) and $route->getOption('_admin_route') === TRUE (MenuLinkContentUITest).

What we do not test is $route->getOption('_admin_route') === FALSE, i.e. have an entity type whose edit form lives under /admin but (like the blocks demo page) does not use the admin theme.

In theory, explicit tests would be preferable over implicit tests, but given that an entire entity type needs to be created for each test case, I'm not super excited that.

So holding off on more test coverage for now, but ...

Gábor Hojtsy’s picture

Issue tags: +D8MI, +language-content, +sprint
Gábor Hojtsy’s picture

For test coverage I was looking if you can just add a route subscriber to remove the admin route option, but looks like hasOption() checks for the array keys and there is no unsetOption() or removeOption(). Also the setOptions() does not override existings options, so it does not seem to be useful to unset options. Should routes support that somehow at least for testing?

tstoeckler’s picture

@Gábor Hojtsy: Ahh yes, Route::getOptions() does array_key_exists(). That sucks, I wasn't aware of that. Will open a Symfony PR for a removeOption() if I get to it.

You're right though, that we could use #2350503: Add route generation handlers for entities to re-use an existing test entity type instead of providing a bunch of new ones. That's a great idea, thanks!

Gábor Hojtsy’s picture

Status: Needs review » Needs work
Issue tags: +Need tests
Gábor Hojtsy’s picture

Issue tags: -sprint

Not being worked on actively, removing from sprint.

kerby70’s picture

Issue tags: -Need tests +Needs tests

Correcting non standard tag 'Need tests' to 'Needs tests'

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

quietone’s picture

Issue summary: View changes
Status: Needs work » Postponed (maintainer needs more info)
Issue tags: +Bug Smash Initiative

This was an issue in a bugsmash group triage meeting. I was the only who looked at this and I don't know routing but I see that the proposed changes in the patch are not in core. I am going to set this to get more information to confirm that this is still and issue and that this should be pursued.

If this issue still relevant?

Version: 9.5.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.