Updated: Comment 0

Problem/Motivation

As a follow up of #2027115: Allow views to override existing routing items we need to support keeping parameters in the path of routes
in order to be able to provide a view for the taxonomy/term/{taxonomy_term} route.

Proposed resolution

Remaining tasks

User interface changes

API changes

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dawehner’s picture

Status: Active » Needs review
Issue tags: +PHPUnit, +WSCCI
FileSize
26.07 KB

There we go. This adds quite a lot of additional test coverage but this was just needed in order to be sure that nothing breaks.

For sure we should maybe just get in the taxonomy/term/{} example in order to be sure that stuff works in a real world scenario.

tstoeckler’s picture

tstoeckler’s picture

Issue tags: +PHPUnit, +WSCCI
dawehner’s picture

Issue tags: -WSCCI
FileSize
18.27 KB

Good catch!

dawehner’s picture

Issue tags: +WSCCI

.

dawehner’s picture

Priority: Major » Critical

Given that enabling a view like taxonomy/{term} does not work at the moment I consider this as critical.

#2029509: Add a generic entity argument validation plugin.

damiankloip’s picture

  1. +++ b/core/modules/views/lib/Drupal/views/Plugin/views/display/PathPluginBase.php
    @@ -223,6 +225,22 @@ public function alterRoutes(RouteCollection $collection) {
    +        $argument_ids = array_keys($view_arguments);
    ...
    +          $path = str_replace('arg_' . $argument_ids[$key], $parameter, $path);
    

    I know this works, it just seems a bit fragile. I can't see a better way though unfortunately. Maybe some comment about the numeric keys matching up would help?

  2. +++ b/core/modules/views/lib/Drupal/views/Plugin/views/display/PathPluginBase.php
    @@ -223,6 +225,22 @@ public function alterRoutes(RouteCollection $collection) {
    +        foreach ($parameters as $key => $parameter) {
    

    Maybe these vars could be named better. Not sure of anything better right now though :p But the key is the parameter position? and the parameter is actually the param node (that would be in the slug) right?

  3. +++ b/core/modules/views/lib/Drupal/views/Routing/ViewPageController.php
    @@ -65,15 +66,32 @@ public function handle(Request $request) {
    +      // Allow parameters be pulled from
    

    I think this line needs to be finished off? :)

  4. +++ b/core/modules/views/lib/Drupal/views/Routing/ViewPageController.php
    @@ -65,15 +66,32 @@ public function handle(Request $request) {
    +      else {
    +        $arg = $request->attributes->get($attribute);
    +      }
    

    So if it gets to here, it's just a regular views arg, yes?

  5. +++ b/core/modules/views/tests/Drupal/views/Tests/Plugin/display/PathPluginBaseTest.php
    @@ -146,6 +146,42 @@ public function testAlterRoute() {
    +    // Manually setup a argument handler.
    

    an argument handler.

  6. +++ b/core/modules/views/tests/Drupal/views/Tests/Plugin/display/PathPluginBaseTest.php
    @@ -146,6 +146,42 @@ public function testAlterRoute() {
    +    $this->assertTrue($route instanceof Route);
    

    assertInstanceOf

  7. +++ b/core/modules/views/tests/Drupal/views/Tests/Routing/ViewPageControllerTest.php
    @@ -0,0 +1,266 @@
    +
    

    Extra newline.

  8. +++ b/core/modules/views/tests/Drupal/views/Tests/Routing/ViewPageControllerTest.php
    @@ -0,0 +1,266 @@
    +    $this->assertTrue(is_array($output));
    

    assertInternalType?

dawehner’s picture

Issue summary: View changes
FileSize
4.5 KB
18.73 KB

I know this works, it just seems a bit fragile. I can't see a better way though unfortunately. Maybe some comment about the numeric keys matching up would help?

Yeah it is kind of a hack, but I can't think of a better way, do you? We can iterate on that.

Maybe these vars could be named better. Not sure of anything better right now though :p But the key is the parameter position? and the parameter is actually the param node (that would be in the slug) right?

<3 position

So if it gets to here, it's just a regular views arg, yes?

Improved the documentation there.

assertInstanceOf

I personally think the DX is worse with that, but I don't complain here.

dawehner’s picture

Title: Allow overriding views to container parameters » Allow overriding views to override paths with parameters

Changed title.

tim.plunkett’s picture

Status: Needs review » Reviewed & tested by the community
+++ b/core/modules/views/lib/Drupal/views/Plugin/views/display/PathPluginBase.php
@@ -223,6 +225,24 @@ public function alterRoutes(RouteCollection $collection) {
+        $route->setDefault('_view_argument_map', $argument_map);

+++ b/core/modules/views/lib/Drupal/views/Routing/ViewPageController.php
@@ -65,15 +66,37 @@ public function handle(Request $request) {
+    $map = $request->attributes->get('_view_argument_map', array());

Brilliant.

This looks great, let's get it in.

Dries’s picture

Status: Reviewed & tested by the community » Fixed

Committed to 8.x. Thanks!

dawehner’s picture

Awesome, thank you very much!

Status: Fixed » Closed (fixed)

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