diff --git a/core/modules/user/src/Tests/Views/FilterPermissionUiTest.php b/core/modules/user/src/Tests/Views/FilterPermissionUiTest.php new file mode 100644 index 0000000..6420847 --- /dev/null +++ b/core/modules/user/src/Tests/Views/FilterPermissionUiTest.php @@ -0,0 +1,72 @@ +enableViewsTestModule(); + } + + /** + * Tests basic filter handler settings in the UI. + */ + public function testHandlerUI() { + $this->drupalLogin($this->drupalCreateUser(['administer views', 'administer users'])); + + $this->drupalGet('admin/structure/views/view/test_filter_permission/edit/default'); + // Verify that the handler summary is correctly displaying the selected + // permission. + $this->assertLink('User: Permission (= View user information)'); + $this->drupalPostForm(NULL, [], 'Save'); + // Verify that we can save the view. + $this->assertNoText('No valid values found on filter: User: Permission.'); + $this->assertText('The view test_filter_permission has been saved.'); + + // Verify that the handler summary is also correct when multiple values are + // selected in the filter. + $edit = [ + 'options[value][]' => [ + 'access user profiles', + 'administer views', + ], + ]; + $this->drupalPostForm('admin/structure/views/nojs/handler/test_filter_permission/default/filter/permission', $edit, 'Apply'); + $this->assertLink('User: Permission (or View us…)'); + $this->drupalPostForm(NULL, [], 'Save'); + // Verify that we can save the view. + $this->assertNoText('No valid values found on filter: User: Permission.'); + $this->assertText('The view test_filter_permission has been saved.'); + } + +} diff --git a/core/modules/views/src/Plugin/views/filter/InOperator.php b/core/modules/views/src/Plugin/views/filter/InOperator.php index d08aa00..4dec210 100644 --- a/core/modules/views/src/Plugin/views/filter/InOperator.php +++ b/core/modules/views/src/Plugin/views/filter/InOperator.php @@ -330,6 +330,8 @@ public function adminSummary() { $info = $this->operators(); $this->getValueOptions(); + // Some filter_in_operator usage uses optgroups forms, so flatten it. + $flat_options = OptGroup::flattenOptions($this->valueOptions); if (!is_array($this->value)) { return; @@ -340,7 +342,7 @@ public function adminSummary() { if (in_array($this->operator, $this->operatorValues(1))) { // Remove every element which is not known. foreach ($this->value as $value) { - if (!isset($this->valueOptions[$value])) { + if (!isset($flat_options[$value])) { unset($this->value[$value]); } } @@ -356,8 +358,8 @@ public function adminSummary() { $keys = $this->value; $value = array_shift($keys); - if (isset($this->valueOptions[$value])) { - $values = SafeMarkup::checkPlain($this->valueOptions[$value]); + if (isset($flat_options[$value])) { + $values = SafeMarkup::checkPlain($flat_options[$value]); } else { $values = ''; @@ -372,8 +374,8 @@ public function adminSummary() { $values = Unicode::truncate($values, 8, FALSE, TRUE); break; } - if (isset($this->valueOptions[$value])) { - $values .= SafeMarkup::checkPlain($this->valueOptions[$value]); + if (isset($flat_options[$value])) { + $values .= SafeMarkup::checkPlain($flat_options[$value]); } } }