We have a situation where we need a summary view (done as in glossary mode using the first letter of the last name) on an embed view display that lists people. This type of glossary filtering is a relatively common request.

We don't want to use page displays for a number of reasons, so this embed view is displayed within a node entity (as part of a paragraph type but that is likely unimportant.)

The key is that we need to be able to set a base path for the summary links and not let Drupal simply use the path of the first view page display (of which there is not one.)

Attachments are allowed on embed displays: #2886613: Allow Attachments on Embed Displays so this does seem like necessary functionality.

The base path field in the contextual filter options says: "Define the base path for links in this summary view, i.e. http://example.com/your_view_path/archive. Do not include beginning and ending forward slash. If this value is empty, views will use the first path found as the base path, in page displays, or / if no path could be found."

When no base path is entered, the summary links fallback as expected to / which obviously won't work for us but doesn't throw an error.

When a base path is entered such as 'super-page' (no beginning or ending slashes), I would expect that the summary links would then use "super-page/[letter argument]". However, instead the view completely fails to load and throws the following error:

Symfony\Component\Routing\Exception\InvalidParameterException: Parameter "node" for route "entity.node.canonical" must match "\d+" ("s" given) to generate a corresponding URL. in Drupal\Core\Routing\UrlGenerator->doGenerate() (line 204 of /web/core/lib/Drupal/Core/Routing/UrlGenerator.php).

This error occurs both when using "node/[nid]" and when using the path alias of the node.

Issue fork drupal-3054944

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

jastraat created an issue. See original summary.

jastraat’s picture

Issue summary: View changes
jastraat’s picture

Issue summary: View changes
jastraat’s picture

Title: Base path for attachment summary view on embed display broken » Base path for attachment summary view broken

Using the base path option on a summary view attachment attached to either a block or embed display errors.

kle’s picture

Same situation: Drupal 8.6.17 - "Define the base path for links in this summary view" will not work (Paths on glossar-Items is )

Version: 8.7.1 » 8.7.x-dev

Core issues are now filed against the dev versions where changes will be made. Document the specific release you are using in your issue comment. More information about choosing a version.

Version: 8.7.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. Branches prior to 8.8.x are not supported, and 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
damienmckenna’s picture

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

Just ran into this problem with EVA. Argh.

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.

matslats’s picture

I'm having a similar issue although it looks like the InvalidParameterException has been fixed.
Now the base path is simply ignored as if the value were ''.
My view has two glossary embed display, one for the given name and one for the family name.
I looked in
This is where the glossaries are rendered.
The first argument for the given name is passed into the first url parameter, resulting in a correct path of /a.
The second argument, which has a base path of 'all' is also passed into the first url parameter, resulting in a path of '/A' instead of '/all/A'.
This all happens in function template_preprocess_views_view_summary_unformatted():

// $view->args is already set to ['a', NULL] for the first glossary and ['A', NULL for the second glossary]
//For the latter, the base path has already been merged with the views arguments.
routeParameters: array[
  "arg_0" => "all"
  "arg_1" => null
  "view_id" => "my_view"
  "display_id" => "my_display"
]
But then parameter 1 overwrites arg_0 instead of being appended to it.
foreach ($route_variables as $variable_name) { // arg_0, arg_1
  $parameters[$variable_name] = array_shift($args);
}

The first parameter should not be in the first position, but the first free position.
Therefore, for this purpose at least, it can be fixed by appending parameters after the ones already set:

foreach ($route_variables as $variable_name) { // arg_0, arg_1
  if (is_null($parameters[$variable_name])) {
    $parameters[$variable_name] = array_shift($args);
  }
}

Finding the first argument already set with the base_path, it puts the first argument in the second position so that now arg_1 carries the first glossary letter A of the family name.

The temporary fix is to overwrite the theme function. Here's my gutted version

function my_module_preprocess_views_view_summary_unformatted($variables) {
  $view = $variables['view'];
  $argument = $view->argument[$view->build_info['summary_level']];
  $row_args = [];
  foreach ($variables['rows'] as $id => $row) {
    $row_args[$id] = $argument->summaryArgument($row);
  }
  $argument->processSummaryArguments($row_args);
  foreach ($variables['rows'] as $id => $row) {
    $args = $view->args;
    $args[$argument->position] = $row_args[$id];
    if (!empty($argument->options['summary_options']['base_path'])) {
      $base_path = $argument->options['summary_options']['base_path'];
      $tokens = $view->getDisplay()->getArgumentsTokens();
      $base_path = $argument->globalTokenReplace($base_path, $tokens);
      $url = Url::fromUserInput('/' . $base_path);
      $route = \Drupal::service('router.route_provider')->getRouteByName($url->getRouteName());
      $route_variables = $route->compile()->getVariables(); // arg_0, arg_1
      $parameters = $url->getRouteParameters();
      foreach ($route_variables as $variable_name) {
        if (is_null($parameters[$variable_name])) {
          $parameters[$variable_name] = array_shift($args);
        }
      }
      $variables['rows'][$id]->url = $url->setRouteParameters($parameters)->toString();
    }
  }
}

Additional question:
What if the second glossary had too many elements in the base path? This would break this mechanism. couldn't the base_path be populated automatically using the 'all' parameter for each of the preceding views arguments?

vitaliyb98 made their first commit to this issue’s fork.

vitaliyb98’s picture

I believe that for displays not extending PathPluginBase, the summary option for arguments should not be available at least until this is fixed or a better solution is found.

I've added a basic solution as a draft, and I’d be interested to hear your thoughts on it.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.