Commit 1d13c5f1 authored by alexpott's avatar alexpott

Issue #2685021 by Lendude, cilefen, r0nn1ef, andypost: Fatal error: $this when...

Issue #2685021 by Lendude, cilefen, r0nn1ef, andypost: Fatal error: $this when not in object context in views.theme.inc
parent 2c35bee1
...@@ -20,7 +20,7 @@ class StyleSummaryTest extends ViewTestBase { ...@@ -20,7 +20,7 @@ class StyleSummaryTest extends ViewTestBase {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public static $modules = ['entity_test']; public static $modules = ['entity_test', 'views_ui'];
/** /**
* {@inheritdoc} * {@inheritdoc}
...@@ -48,6 +48,9 @@ protected function setUp($import_test_views = TRUE) { ...@@ -48,6 +48,9 @@ protected function setUp($import_test_views = TRUE) {
$entity->save(); $entity->save();
} }
} }
$views_user = $this->drupalCreateUser(['administer views']);
$this->drupalLogin($views_user);
} }
/** /**
...@@ -72,6 +75,71 @@ public function testSummaryView() { ...@@ -72,6 +75,71 @@ public function testSummaryView() {
$this->clickLink('type1'); $this->clickLink('type1');
$entries = $this->cssSelect('div.view-content div.views-row'); $entries = $this->cssSelect('div.view-content div.views-row');
$this->assertEqual(2, count($entries)); $this->assertEqual(2, count($entries));
// Add a base path to the summary settings.
$edit = [
'options[summary][options][default_summary][base_path]' => 'test-summary',
];
$this->drupalPostForm('admin/structure/views/nojs/handler/test_summary/page_1/argument/type', $edit, t('Apply'));
$this->drupalPostForm(NULL, [], t('Save'));
// Test that the links still work.
$this->drupalGet('test-summary');
$this->clickLink('type1');
$entries = $this->cssSelect('div.view-content div.views-row');
$this->assertEqual(2, count($entries));
// Change the summary display to an unformatted list displaying 3 items.
$edit = [
'options[summary][format]' => 'unformatted_summary',
'options[summary][options][unformatted_summary][override]' => '1',
'options[summary][options][unformatted_summary][items_per_page]' => '3',
];
$this->drupalPostForm('admin/structure/views/nojs/handler/test_summary/page_1/argument/type', $edit, t('Apply'));
$this->drupalPostForm(NULL, [], t('Save'));
$this->drupalGet('admin/structure/views/nojs/handler/test_summary/page_1/argument/type');
$this->drupalGet('test-summary');
$summary_list = $this->cssSelect('.views-summary-unformatted');
$this->assertEqual(3, count($summary_list));
foreach ($summary_list as $summary_list_item) {
$this->assertEqual('(5)', trim((string) $summary_list_item));
}
$summary_links = $this->cssSelect('.views-summary-unformatted a');
$this->assertEqual(3, count($summary_links));
foreach ($summary_links as $index => $summary_link) {
$this->assertEqual('type' . $index, trim((string) $summary_link));
}
$this->clickLink('type1');
$entries = $this->cssSelect('div.view-content div.views-row');
$this->assertEqual(2, count($entries));
// Add a base path to the summary settings.
$edit = [
'options[summary][options][unformatted_summary][base_path]' => 'test-summary',
];
$this->drupalPostForm('admin/structure/views/nojs/handler/test_summary/page_1/argument/type', $edit, t('Apply'));
$this->drupalPostForm(NULL, [], t('Save'));
// Test that the links still work.
$this->drupalGet('test-summary');
$this->clickLink('type1');
$entries = $this->cssSelect('div.view-content div.views-row');
$this->assertEqual(2, count($entries));
// Set base_path to an unknown path and test that the links lead to the
// front page.
$edit = [
'options[summary][options][unformatted_summary][base_path]' => 'unknown-path',
];
$this->drupalPostForm('admin/structure/views/nojs/handler/test_summary/page_1/argument/type', $edit, t('Apply'));
$this->drupalPostForm(NULL, [], t('Save'));
$this->drupalGet('test-summary');
$this->assertLinkByHref('/');
} }
} }
...@@ -75,6 +75,7 @@ display: ...@@ -75,6 +75,7 @@ display:
specify_validation: true specify_validation: true
plugin_id: string plugin_id: string
entity_type: entity_test entity_type: entity_test
admin_label: type
fields: fields:
id: id:
id: id id: id
......
...@@ -277,11 +277,29 @@ function template_preprocess_views_view_summary(&$variables) { ...@@ -277,11 +277,29 @@ function template_preprocess_views_view_summary(&$variables) {
if (!empty($argument->options['summary_options']['base_path'])) { if (!empty($argument->options['summary_options']['base_path'])) {
$base_path = $argument->options['summary_options']['base_path']; $base_path = $argument->options['summary_options']['base_path'];
$tokens = $this->getArgumentsTokens(); $tokens = $view->getDisplay()->getArgumentsTokens();
$base_path = $this->viewsTokenReplace($base_path, $tokens); $base_path = $argument->globalTokenReplace($base_path, $tokens);
// @todo Views should expect and store a leading /. See: // @todo Views should expect and store a leading /. See:
// https://www.drupal.org/node/2423913 // https://www.drupal.org/node/2423913
$url = Url::fromUserInput('/' . $base_path); $url = Url::fromUserInput('/' . $base_path);
try {
/** @var \Symfony\Component\Routing\Route $route */
$route_name = $url->getRouteName();
$route = \Drupal::service('router.route_provider')->getRouteByName($route_name);
$route_variables = $route->compile()->getVariables();
$parameters = $url->getRouteParameters();
foreach ($route_variables as $variable_name) {
$parameters[$variable_name] = array_shift($args);
}
$url->setRouteParameters($parameters);
}
catch (Exception $e) {
// If the given route doesn't exist, default to <front>
$url = Url::fromRoute('<front>');
}
} }
else { else {
$url = $view->getUrl($args)->setOptions($url_options); $url = $view->getUrl($args)->setOptions($url_options);
...@@ -307,6 +325,7 @@ function template_preprocess_views_view_summary(&$variables) { ...@@ -307,6 +325,7 @@ function template_preprocess_views_view_summary(&$variables) {
* visually distinct. * visually distinct.
*/ */
function template_preprocess_views_view_summary_unformatted(&$variables) { function template_preprocess_views_view_summary_unformatted(&$variables) {
/** @var \Drupal\views\ViewExecutable $view */
$view = $variables['view']; $view = $variables['view'];
$argument = $view->argument[$view->build_info['summary_level']]; $argument = $view->argument[$view->build_info['summary_level']];
...@@ -346,11 +365,27 @@ function template_preprocess_views_view_summary_unformatted(&$variables) { ...@@ -346,11 +365,27 @@ function template_preprocess_views_view_summary_unformatted(&$variables) {
if (!empty($argument->options['summary_options']['base_path'])) { if (!empty($argument->options['summary_options']['base_path'])) {
$base_path = $argument->options['summary_options']['base_path']; $base_path = $argument->options['summary_options']['base_path'];
$tokens = $this->getArgumentsTokens(); $tokens = $view->getDisplay()->getArgumentsTokens();
$base_path = $this->viewsTokenReplace($base_path, $tokens); $base_path = $argument->globalTokenReplace($base_path, $tokens);
// @todo Views should expect and store a leading /. See: // @todo Views should expect and store a leading /. See:
// https://www.drupal.org/node/2423913 // https://www.drupal.org/node/2423913
$url = Url::fromUserInput('/' . $base_path); $url = Url::fromUserInput('/' . $base_path);
try {
/** @var \Symfony\Component\Routing\Route $route */
$route = \Drupal::service('router.route_provider')->getRouteByName($url->getRouteName());
$route_variables = $route->compile()->getVariables();
$parameters = $url->getRouteParameters();
foreach ($route_variables as $variable_name) {
$parameters[$variable_name] = array_shift($args);
}
$url->setRouteParameters($parameters);
}
catch (Exception $e) {
// If the given route doesn't exist, default to <front>
$url = Url::fromRoute('<front>');
}
} }
else { else {
$url = $view->getUrl($args)->setOptions($url_options); $url = $view->getUrl($args)->setOptions($url_options);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment