summaryrefslogtreecommitdiffstatshomepage
path: root/core/modules/views
diff options
context:
space:
mode:
Diffstat (limited to 'core/modules/views')
-rw-r--r--core/modules/views/js/ajax_view.js2
-rw-r--r--core/modules/views/src/Entity/View.php2
-rw-r--r--core/modules/views/src/Form/ViewsExposedForm.php1
-rw-r--r--core/modules/views/src/Plugin/views/display/DisplayPluginBase.php7
-rw-r--r--core/modules/views/tests/modules/views_test_config/test_views/views.view.test_third_party_uninstall.yml37
-rw-r--r--core/modules/views/tests/modules/views_third_party_settings_test/config/schema/views_third_party_settings_test.schema.yml7
-rw-r--r--core/modules/views/tests/modules/views_third_party_settings_test/views_third_party_settings_test.info.yml8
-rw-r--r--core/modules/views/tests/src/Functional/GlossaryTest.php1
-rw-r--r--core/modules/views/tests/src/Functional/Plugin/DisplayTest.php13
-rw-r--r--core/modules/views/tests/src/Kernel/Handler/ArgumentSummaryTest.php34
-rw-r--r--core/modules/views/tests/src/Kernel/Plugin/ExposedFormRenderTest.php5
-rw-r--r--core/modules/views/tests/src/Kernel/ThirdPartyUninstallTest.php55
-rw-r--r--core/modules/views/views.theme.inc14
13 files changed, 168 insertions, 18 deletions
diff --git a/core/modules/views/js/ajax_view.js b/core/modules/views/js/ajax_view.js
index dd3da9b8350..8e646697d83 100644
--- a/core/modules/views/js/ajax_view.js
+++ b/core/modules/views/js/ajax_view.js
@@ -83,7 +83,7 @@
if (queryString !== '') {
// If there is a '?' in ajaxPath, clean URL are on and & should be
// used to add parameters.
- queryString = (/\?/.test(ajaxPath) ? '&' : '?') + queryString;
+ queryString = (ajaxPath.includes('?') ? '&' : '?') + queryString;
}
}
diff --git a/core/modules/views/src/Entity/View.php b/core/modules/views/src/Entity/View.php
index cd1b2a0a42e..f6bb32cec87 100644
--- a/core/modules/views/src/Entity/View.php
+++ b/core/modules/views/src/Entity/View.php
@@ -481,7 +481,7 @@ class View extends ConfigEntityBase implements ViewEntityInterface {
* {@inheritdoc}
*/
public function onDependencyRemoval(array $dependencies) {
- $changed = FALSE;
+ $changed = parent::onDependencyRemoval($dependencies);
// Don't intervene if the views module is removed.
if (isset($dependencies['module']) && in_array('views', $dependencies['module'])) {
diff --git a/core/modules/views/src/Form/ViewsExposedForm.php b/core/modules/views/src/Form/ViewsExposedForm.php
index d68b1dd5363..9f90160ff55 100644
--- a/core/modules/views/src/Form/ViewsExposedForm.php
+++ b/core/modules/views/src/Form/ViewsExposedForm.php
@@ -196,7 +196,6 @@ class ViewsExposedForm extends FormBase implements WorkspaceSafeFormInterface {
$view->exposed_data = $values;
$view->exposed_raw_input = [];
- $exclude = ['submit', 'form_build_id', 'form_id', 'form_token', 'exposed_form_plugin', 'reset'];
/** @var \Drupal\views\Plugin\views\exposed_form\ExposedFormPluginBase $exposed_form_plugin */
$exposed_form_plugin = $view->display_handler->getPlugin('exposed_form');
$exposed_form_plugin->exposedFormSubmit($form, $form_state, $exclude);
diff --git a/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php b/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php
index fc4a983f929..d3adc61de5a 100644
--- a/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php
+++ b/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php
@@ -2117,13 +2117,18 @@ abstract class DisplayPluginBase extends PluginBase implements DisplayPluginInte
$hasMoreRecords = !empty($this->view->pager) && $this->view->pager->hasMoreRecords();
if ($this->isMoreEnabled() && ($this->useMoreAlways() || $hasMoreRecords)) {
$url = $this->getMoreUrl();
+ $access = $url->access(return_as_object: TRUE);
- return [
+ $more_link = [
'#type' => 'more_link',
'#url' => $url,
'#title' => $this->useMoreText(),
'#view' => $this->view,
+ '#access' => $access->isAllowed(),
];
+ $accessCacheability = CacheableMetadata::createFromObject($access);
+ $accessCacheability->applyTo($more_link);
+ return $more_link;
}
}
diff --git a/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_third_party_uninstall.yml b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_third_party_uninstall.yml
new file mode 100644
index 00000000000..eb59548f17f
--- /dev/null
+++ b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_third_party_uninstall.yml
@@ -0,0 +1,37 @@
+langcode: en
+status: true
+dependencies:
+ module:
+ - node
+ - views_third_party_settings_test
+third_party_settings:
+ views_third_party_settings_test:
+ example_setting: true
+id: test_third_party_uninstall
+label: test_third_party_uninstall
+module: views
+description: ''
+tag: ''
+base_table: node_field_data
+base_field: nid
+display:
+ default:
+ display_options:
+ access:
+ type: none
+ cache:
+ type: tag
+ exposed_form:
+ type: basic
+ pager:
+ type: full
+ query:
+ type: views_query
+ style:
+ type: default
+ row:
+ type: fields
+ display_plugin: default
+ display_title: Defaults
+ id: default
+ position: 0
diff --git a/core/modules/views/tests/modules/views_third_party_settings_test/config/schema/views_third_party_settings_test.schema.yml b/core/modules/views/tests/modules/views_third_party_settings_test/config/schema/views_third_party_settings_test.schema.yml
new file mode 100644
index 00000000000..0bdeeed705a
--- /dev/null
+++ b/core/modules/views/tests/modules/views_third_party_settings_test/config/schema/views_third_party_settings_test.schema.yml
@@ -0,0 +1,7 @@
+views.view.*.third_party.views_third_party_settings_test:
+ type: config_entity
+ label: "Example settings"
+ mapping:
+ example_setting:
+ type: boolean
+ label: "Example setting"
diff --git a/core/modules/views/tests/modules/views_third_party_settings_test/views_third_party_settings_test.info.yml b/core/modules/views/tests/modules/views_third_party_settings_test/views_third_party_settings_test.info.yml
new file mode 100644
index 00000000000..be975279565
--- /dev/null
+++ b/core/modules/views/tests/modules/views_third_party_settings_test/views_third_party_settings_test.info.yml
@@ -0,0 +1,8 @@
+name: 'Third Party Settings Test'
+type: module
+description: 'A dummy module that third party settings tests can depend on'
+package: Testing
+version: VERSION
+dependencies:
+ - drupal:node
+ - drupal:views
diff --git a/core/modules/views/tests/src/Functional/GlossaryTest.php b/core/modules/views/tests/src/Functional/GlossaryTest.php
index 292f9176771..25c08d5f159 100644
--- a/core/modules/views/tests/src/Functional/GlossaryTest.php
+++ b/core/modules/views/tests/src/Functional/GlossaryTest.php
@@ -83,7 +83,6 @@ class GlossaryTest extends ViewTestBase {
'url',
'user.node_grants:view',
'user.permissions',
- 'route',
],
[
'config:views.view.glossary',
diff --git a/core/modules/views/tests/src/Functional/Plugin/DisplayTest.php b/core/modules/views/tests/src/Functional/Plugin/DisplayTest.php
index 8af887d1ef1..5aecbea3e36 100644
--- a/core/modules/views/tests/src/Functional/Plugin/DisplayTest.php
+++ b/core/modules/views/tests/src/Functional/Plugin/DisplayTest.php
@@ -4,7 +4,6 @@ declare(strict_types=1);
namespace Drupal\Tests\views\Functional\Plugin;
-use Drupal\Component\Render\FormattableMarkup;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\Tests\views\Functional\ViewTestBase;
use Drupal\views\Views;
@@ -317,6 +316,14 @@ class DisplayTest extends ViewTestBase {
$output = $view->preview();
$output = (string) $renderer->renderRoot($output);
$this->assertStringContainsString('/node?date=22&foo=bar#22', $output, 'The read more link with href "/node?date=22&foo=bar#22" was found.');
+
+ // Test more link isn't rendered if user doesn't have permission to the
+ // more link URL.
+ $view->display_handler->setOption('link_url', 'admin/content');
+ $this->executeView($view);
+ $output = $view->preview();
+ $output = (string) $renderer->renderRoot($output);
+ $this->assertStringNotContainsString('/admin/content', $output, 'The read more link with href "/admin/content" was not found.');
}
/**
@@ -389,8 +396,8 @@ class DisplayTest extends ViewTestBase {
$errors = $view->validate();
// Check that the error messages are shown.
$this->assertCount(2, $errors['default'], 'Error messages found for required relationship');
- $this->assertEquals(new FormattableMarkup('The %relationship_name relationship used in %handler_type %handler is not present in the %display_name display.', ['%relationship_name' => 'uid', '%handler_type' => 'field', '%handler' => 'User: Last login', '%display_name' => 'Default']), $errors['default'][0]);
- $this->assertEquals(new FormattableMarkup('The %relationship_name relationship used in %handler_type %handler is not present in the %display_name display.', ['%relationship_name' => 'uid', '%handler_type' => 'field', '%handler' => 'User: Created', '%display_name' => 'Default']), $errors['default'][1]);
+ $this->assertEquals("The uid relationship used in field User: Last login is not present in the Default display.", $errors['default'][0]);
+ $this->assertEquals("The uid relationship used in field User: Created is not present in the Default display.", $errors['default'][1]);
}
/**
diff --git a/core/modules/views/tests/src/Kernel/Handler/ArgumentSummaryTest.php b/core/modules/views/tests/src/Kernel/Handler/ArgumentSummaryTest.php
index 03488125064..e19f1414615 100644
--- a/core/modules/views/tests/src/Kernel/Handler/ArgumentSummaryTest.php
+++ b/core/modules/views/tests/src/Kernel/Handler/ArgumentSummaryTest.php
@@ -150,4 +150,38 @@ class ArgumentSummaryTest extends ViewsKernelTestBase {
$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);
+ }
+
}
diff --git a/core/modules/views/tests/src/Kernel/Plugin/ExposedFormRenderTest.php b/core/modules/views/tests/src/Kernel/Plugin/ExposedFormRenderTest.php
index 97d670634b3..14f90fd0c33 100644
--- a/core/modules/views/tests/src/Kernel/Plugin/ExposedFormRenderTest.php
+++ b/core/modules/views/tests/src/Kernel/Plugin/ExposedFormRenderTest.php
@@ -137,12 +137,13 @@ class ExposedFormRenderTest extends ViewsKernelTestBase {
$view->save();
$this->executeView($view);
+ // The "type" filter should be excluded from the raw input because its
+ // value is "All".
$expected = [
- 'type' => 'All',
'type_with_default_value' => 'article',
'multiple_types_with_default_value' => ['article' => 'article'],
];
- $this->assertSame($view->exposed_raw_input, $expected);
+ $this->assertSame($expected, $view->exposed_raw_input);
}
}
diff --git a/core/modules/views/tests/src/Kernel/ThirdPartyUninstallTest.php b/core/modules/views/tests/src/Kernel/ThirdPartyUninstallTest.php
new file mode 100644
index 00000000000..0f3d3eb5291
--- /dev/null
+++ b/core/modules/views/tests/src/Kernel/ThirdPartyUninstallTest.php
@@ -0,0 +1,55 @@
+<?php
+
+declare(strict_types=1);
+
+namespace Drupal\Tests\views\Kernel;
+
+use Drupal\views\Entity\View;
+
+/**
+ * Tests proper removal of third-party settings from views.
+ *
+ * @group views
+ */
+class ThirdPartyUninstallTest extends ViewsKernelTestBase {
+
+ /**
+ * {@inheritdoc}
+ */
+ protected static $modules = ['node', 'views_third_party_settings_test'];
+
+ /**
+ * Views used by this test.
+ *
+ * @var array
+ */
+ public static $testViews = ['test_third_party_uninstall'];
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function setUp($import_test_views = TRUE): void {
+ parent::setUp($import_test_views);
+
+ $this->installEntitySchema('user');
+ $this->installSchema('user', ['users_data']);
+ }
+
+ /**
+ * Tests removing third-party settings when a provider module is uninstalled.
+ */
+ public function testThirdPartyUninstall(): void {
+ $view = View::load('test_third_party_uninstall');
+ $this->assertNotEmpty($view);
+ $this->assertContains('views_third_party_settings_test', $view->getDependencies()['module']);
+ $this->assertTrue($view->getThirdPartySetting('views_third_party_settings_test', 'example_setting'));
+
+ \Drupal::service('module_installer')->uninstall(['views_third_party_settings_test']);
+
+ $view = View::load('test_third_party_uninstall');
+ $this->assertNotEmpty($view);
+ $this->assertNotContains('views_third_party_settings_test', $view->getDependencies()['module']);
+ $this->assertNull($view->getThirdPartySetting('views_third_party_settings_test', 'example_setting'));
+ }
+
+}
diff --git a/core/modules/views/views.theme.inc b/core/modules/views/views.theme.inc
index 10c29c5dbf3..04c5de5a535 100644
--- a/core/modules/views/views.theme.inc
+++ b/core/modules/views/views.theme.inc
@@ -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);