Problem/Motivation

Follow up to #2443119: Views preview not working for REST display

Dynamic routes in views should be prefixed with views.view rather then view, to increase maintainability we need to think about introducing a prefix constant here.

While we are fixing routes in views, RouteSubscriber::alterRoutes() should be cleaned up, we should not remove the route from the collection there since this is already handled in PathPluginBase::alterRoutes

Remaining tasks

Change dynamic route prefix from view to views.view
Create a route prefix constant and us that to prefix any dynamic routes in views
Cleanup RouteSubscriber::alterRoutes()

User interface changes

None

API changes

Introduce prefix constant

Beta phase evaluation

Reference: https://www.drupal.org/core/beta-changes
Issue category Task because view. works as a prefix
Prioritized changes This reduces fragility by ensuring that routes creates by the Views module begin with views. And to make it easy to not introduce code bugs by incorrectly prefixing a views dynamic route.
Disruption Not disruptive - all existing sites will have to do is rebuild their menu router

Comments

geertvd’s picture

geertvd’s picture

Issue summary: View changes
geertvd’s picture

Issue summary: View changes
alexpott’s picture

Issue summary: View changes
Status: Active » Needs review
StatusFileSize
new19.91 KB

Here's a patch that carries out the tasks described in the issue summary. I guess we might have some simpletest failures.

Status: Needs review » Needs work

The last submitted patch, 4: 2450055.4.patch, failed testing.

alexpott’s picture

Status: Needs work » Needs review
StatusFileSize
new569 bytes
new19.9 KB

Maybe the disruption of actually changing the prefix is not worth it.

Status: Needs review » Needs work

The last submitted patch, 6: 2450055.6.patch, failed testing.

alexpott’s picture

Status: Needs work » Needs review
StatusFileSize
new467 bytes
new20.11 KB
dawehner’s picture

  1. +++ b/core/modules/views/src/Plugin/Derivative/ViewsLocalTask.php
    @@ -70,7 +71,7 @@ public function getDerivativeDefinitions($base_plugin_definition) {
    -        $plugin_id = 'view.' . $executable->storage->id() . '.' . $display_id;
    +        $plugin_id = DisplayRouterInterface::PREFIX . $executable->storage->id() . '.' . $display_id;
    

    Its a bit odd that its part of the interface ... I think, but I don't have a better suggestion.

  2. +++ b/core/modules/views/src/Plugin/views/display/DisplayRouterInterface.php
    @@ -18,6 +18,11 @@
       /**
    +   * Prefix added to the beginning of a view entity's dynamic routes.
    +   */
    +  const PREFIX = 'view.';
    

    What about at least naming it ROUTE_NAME_PREFIX?

  3. +++ b/core/modules/views/tests/src/Unit/EventSubscriber/RouteSubscriberTest.php
    @@ -90,8 +90,7 @@ public function testOnAlterRoutes() {
    -    $route_2 = new Route('test_route/example', array('_controller' => 'Drupal\Tests\Core\Controller\TestController'));
    -    $collection->add('test_route_2', $route_2);
    +    $collection->add('test_route_2', new Route('test_route/example', array('_controller' => 'Drupal\Tests\Core\Controller\TestController')));
    

    +1 This is a bit easier to read.

  4. +++ b/core/modules/views/tests/src/Unit/EventSubscriber/RouteSubscriberTest.php
    @@ -102,18 +101,21 @@ public function testOnAlterRoutes() {
    +        $collection->add('views.view.test_id.page_2', new Route('test_route', ['_controller' => 'Drupal\views\Routing\ViewPageController']));
    
    +++ b/core/modules/views/tests/src/Unit/Plugin/Derivative/ViewsLocalTaskTest.php
    @@ -118,7 +119,8 @@ public function testGetDerivativeDefinitionsWithLocalTask() {
    +    $route_name = DisplayRouterInterface::PREFIX . 'example_view.page_1';
    

    I'm confused, didn't we used view.... as prefix above?

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.

dawehner’s picture

Version: 8.1.x-dev » 9.x-dev
Status: Needs review » Needs work

IMHO at that point its a break without that much of a benefit. Feel free to disagree with me, but I would rather move this to D9.

catch’s picture

Title: Change prefix for views dynamic routes » Add constant for prefix for views dynamic routes
Version: 9.x-dev » 8.3.x-dev
Priority: Normal » Minor

Hmm if we ever want to do this we should add the constant in 8.x and change the vale in 9.x

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

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now 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.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now 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.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now 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.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now 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.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.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.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). 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.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now 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: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

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

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.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.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.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.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now 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.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now 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.

Version: 10.1.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, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Status: Needs work » Postponed (maintainer needs more info)
Issue tags: +stale-issue-cleanup

Thank you for creating this issue to improve Drupal.

We are working to decide if this task is still relevant to a currently supported version of Drupal. There hasn't been any discussion here for over 8 years which suggests that this has either been implemented or is no longer relevant. Your thoughts on this will allow a decision to be made.

Since we need more information to move forward with this issue, the status is now Postponed (maintainer needs more info). If we don't receive additional information to help with the issue, it may be closed after three months.

Thanks!