Unverified Commit 335bc707 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3360996 by prudloff, smustgrave, catch:...

Issue #3360996 by prudloff, smustgrave, catch: template_preprocess_views_view_summary_unformatted() does not set active link when using AJAX

(cherry picked from commit 42fb139e)
parent bc806750
Loading
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -83,7 +83,6 @@ public function testGlossaryView(): void {
        'url',
        'user.node_grants:view',
        'user.permissions',
        'route',
      ],
      [
        'config:views.view.glossary',
+34 −0
Original line number Diff line number Diff line
@@ -149,4 +149,38 @@ public function testArgumentSummary(): void {
    $this->assertStringContainsString($tags[1]->label() . ' (2)', $output);
  }

  /**
   * Tests that the active link is set correctly.
   */
  public function testActiveLink(): void {
    require_once $this->root . '/core/modules/views/views.theme.inc';

    // We need at least one node.
    Node::create([
      'type' => $this->nodeType->id(),
      'title' => $this->randomMachineName(),
    ])->save();

    $view = Views::getView('test_argument_summary');
    $view->execute();
    $view->build();
    $variables = [
      'view' => $view,
      'rows' => $view->result,
    ];

    template_preprocess_views_view_summary_unformatted($variables);
    $this->assertFalse($variables['rows'][0]->active);

    template_preprocess_views_view_summary($variables);
    $this->assertFalse($variables['rows'][0]->active);

    // Checks that the row with the current path is active.
    \Drupal::service('path.current')->setPath('/test-argument-summary');
    template_preprocess_views_view_summary_unformatted($variables);
    $this->assertTrue($variables['rows'][0]->active);
    template_preprocess_views_view_summary($variables);
    $this->assertTrue($variables['rows'][0]->active);
  }

}
+6 −8
Original line number Diff line number Diff line
@@ -253,15 +253,12 @@ function template_preprocess_views_view_summary(&$variables): void {
    $url_options['query'] = $view->exposed_raw_input;
  }

  $currentPath = \Drupal::service('path.current')->getPath();
  $active_urls = [
    // Force system path.
    Url::fromRoute('<current>', [], ['alias' => TRUE])->toString(),
    // Force system path.
    Url::fromRouteMatch(\Drupal::routeMatch())->setOption('alias', TRUE)->toString(),
    // Could be an alias.
    Url::fromRoute('<current>')->toString(),
    Url::fromUserInput($currentPath, ['alias' => TRUE])->toString(),
    // Could be an alias.
    Url::fromRouteMatch(\Drupal::routeMatch())->toString(),
    Url::fromUserInput($currentPath)->toString(),
  ];
  $active_urls = array_combine($active_urls, $active_urls);

@@ -342,11 +339,12 @@ function template_preprocess_views_view_summary_unformatted(&$variables): void {
  }

  $count = 0;
  $currentPath = \Drupal::service('path.current')->getPath();
  $active_urls = [
    // Force system path.
    Url::fromRoute('<current>', [], ['alias' => TRUE])->toString(),
    Url::fromUserInput($currentPath, ['alias' => TRUE])->toString(),
    // Could be an alias.
    Url::fromRoute('<current>')->toString(),
    Url::fromUserInput($currentPath)->toString(),
  ];
  $active_urls = array_combine($active_urls, $active_urls);