Loading core/modules/views/tests/src/Functional/GlossaryTest.php +0 −1 Original line number Diff line number Diff line Loading @@ -83,7 +83,6 @@ public function testGlossaryView(): void { 'url', 'user.node_grants:view', 'user.permissions', 'route', ], [ 'config:views.view.glossary', Loading core/modules/views/tests/src/Kernel/Handler/ArgumentSummaryTest.php +34 −0 Original line number Diff line number Diff line Loading @@ -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); } } core/modules/views/views.theme.inc +6 −8 Original line number Diff line number Diff line Loading @@ -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); Loading Loading @@ -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); Loading Loading
core/modules/views/tests/src/Functional/GlossaryTest.php +0 −1 Original line number Diff line number Diff line Loading @@ -83,7 +83,6 @@ public function testGlossaryView(): void { 'url', 'user.node_grants:view', 'user.permissions', 'route', ], [ 'config:views.view.glossary', Loading
core/modules/views/tests/src/Kernel/Handler/ArgumentSummaryTest.php +34 −0 Original line number Diff line number Diff line Loading @@ -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); } }
core/modules/views/views.theme.inc +6 −8 Original line number Diff line number Diff line Loading @@ -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); Loading Loading @@ -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); Loading