diff --git a/core/modules/node/config/install/views.view.content.yml b/core/modules/node/config/install/views.view.content.yml index 2a44101..3220cb5 100644 --- a/core/modules/node/config/install/views.view.content.yml +++ b/core/modules/node/config/install/views.view.content.yml @@ -325,11 +325,11 @@ display: 1: title: Published operator: '=' - value: '1' + value: true 2: title: Unpublished operator: '=' - value: '0' + value: false plugin_id: boolean entity_type: node entity_field: status diff --git a/core/modules/user/config/install/views.view.user_admin_people.yml b/core/modules/user/config/install/views.view.user_admin_people.yml index ff62509..a19e484 100644 --- a/core/modules/user/config/install/views.view.user_admin_people.yml +++ b/core/modules/user/config/install/views.view.user_admin_people.yml @@ -781,11 +781,11 @@ display: 1: title: Active operator: '=' - value: '1' + value: true 2: title: Blocked operator: '=' - value: '0' + value: false plugin_id: boolean entity_type: user entity_field: status diff --git a/core/modules/views/config/schema/views.data_types.schema.yml b/core/modules/views/config/schema/views.data_types.schema.yml index 06f81ba..91590dc 100644 --- a/core/modules/views/config/schema/views.data_types.schema.yml +++ b/core/modules/views/config/schema/views.data_types.schema.yml @@ -768,26 +768,22 @@ views_filter: type: sequence label: 'Group items' sequence: - - type: views.filter.group_item.[%parent.%parent.%parent.plugin_id] + - type: mapping label: 'Group item' + mapping: + title: + type: label + label: 'Label' + operator: + type: string + label: 'Operator' + value: + type: views.filter_value.[%parent.%parent.%parent.%parent.plugin_id] + label: 'Value' plugin_id: type: string label: 'Plugin ID' -views_filter_group_item: - type: mapping - label: 'Group item' - mapping: - title: - type: label - label: 'Label' - operator: - type: string - label: 'Operator' - value: - type: label - label: 'Value' - views_relationship: type: views_handler mapping: diff --git a/core/modules/views/config/schema/views.filter.schema.yml b/core/modules/views/config/schema/views.filter.schema.yml index 3a97c25..8910310 100644 --- a/core/modules/views/config/schema/views.filter.schema.yml +++ b/core/modules/views/config/schema/views.filter.schema.yml @@ -75,9 +75,6 @@ views.filter.string: required: type: boolean label: 'Required' - value: - type: string - label: 'Value' views.filter_value.numeric: type: mapping @@ -118,17 +115,6 @@ views.filter.standard: type: views_filter label: 'Standard' -views.filter.group_item.*: - type: views_filter_group_item - label: 'Default' - -views.filter.group_item.numeric: - type: views_filter_group_item - label: 'Group items' - mapping: - value: - type: views.filter_value.numeric - # Schema for the views filter value. views.filter_value.boolean: @@ -137,6 +123,9 @@ views.filter_value.boolean: views.filter_value.combine: type: string +views.filter_value.string: + type: string + views.filter.language: type: views.filter.in_operator label: 'Language' diff --git a/core/modules/views/src/Plugin/views/filter/Date.php b/core/modules/views/src/Plugin/views/filter/Date.php index 7e5417f..1944e1f 100644 --- a/core/modules/views/src/Plugin/views/filter/Date.php +++ b/core/modules/views/src/Plugin/views/filter/Date.php @@ -136,7 +136,12 @@ public function acceptExposedInput($input) { } // Store this because it will get overwritten. - $type = $this->value['type']; + if ($this->isAGroup()) { + $type = $this->group_info['type']; + } + else { + $type = $this->value['type']; + } $rc = parent::acceptExposedInput($input); // Don't filter if value(s) are empty. diff --git a/core/modules/views/src/Plugin/views/filter/FilterPluginBase.php b/core/modules/views/src/Plugin/views/filter/FilterPluginBase.php index 3af0e9c..9fd50de 100644 --- a/core/modules/views/src/Plugin/views/filter/FilterPluginBase.php +++ b/core/modules/views/src/Plugin/views/filter/FilterPluginBase.php @@ -990,17 +990,20 @@ protected function buildExposedFiltersGroupForm(&$form, FormStateInterface $form $children = Element::children($row['value']); if (!empty($children)) { foreach ($children as $child) { - foreach ($row['value'][$child]['#states']['visible'] as $state) { - if (isset($state[':input[name="options[group_info][group_items][' . $item_id . '][operator]"]'])) { - $row['value'][$child]['#title'] = ''; + if (!empty($row['value'][$child]['#states']['visible'])) { + foreach ($row['value'][$child]['#states']['visible'] as $state) { + if (isset($state[':input[name="options[group_info][group_items][' . $item_id . '][operator]"]'])) { + $row['value'][$child]['#title'] = ''; - if (!empty($this->options['group_info']['group_items'][$item_id]['value'][$child])) { - $row['value'][$child]['#default_value'] = $this->options['group_info']['group_items'][$item_id]['value'][$child]; + // Exit this loop and process the next child element. + break; } - // Exit this loop and process the next child element. - break; } } + + if (!empty($this->options['group_info']['group_items'][$item_id]['value'][$child])) { + $row['value'][$child]['#default_value'] = $this->options['group_info']['group_items'][$item_id]['value'][$child]; + } } } else { diff --git a/core/modules/views/src/Tests/Handler/FilterDateTest.php b/core/modules/views/src/Tests/Handler/FilterDateTest.php index c538bc3..c4fb8cb 100644 --- a/core/modules/views/src/Tests/Handler/FilterDateTest.php +++ b/core/modules/views/src/Tests/Handler/FilterDateTest.php @@ -7,6 +7,7 @@ namespace Drupal\views\Tests\Handler; +use Drupal\config\Tests\SchemaCheckTestTrait; use Drupal\views\Views; /** @@ -15,6 +16,7 @@ * @group views */ class FilterDateTest extends HandlerTestBase { + use SchemaCheckTestTrait; /** * Views used by this test. @@ -51,6 +53,7 @@ protected function testDateFilter() { $this->_testOffset(); $this->_testBetween(); $this->_testUiValidation(); + $this->_testFilterDateUI(); } /** @@ -158,4 +161,83 @@ protected function _testUiValidation() { $this->assertText(t('Invalid date format.'), 'Make sure that validation is runned and the invalidate date format is identified.'); } + /** + * Test date filter UI. + */ + protected function _testFilterDateUI() { + $this->drupalLogin($this->drupalCreateUser(array('administer views'))); + $this->drupalGet('admin/structure/views/nojs/handler/test_filter_date_between/default/filter/created'); + $this->drupalPostForm(NULL, array(), t('Expose filter')); + $this->drupalPostForm(NULL, array(), t('Grouped filters')); + + $edit = array(); + $edit['options[group_info][group_items][1][title]'] = 'simple-offset'; + $edit['options[group_info][group_items][1][operator]'] = '>'; + $edit['options[group_info][group_items][1][value][type]'] = 'offset'; + $edit['options[group_info][group_items][1][value][value]'] = '+1 hour'; + $edit['options[group_info][group_items][2][title]'] = 'between-offset'; + $edit['options[group_info][group_items][2][operator]'] = 'between'; + $edit['options[group_info][group_items][2][value][type]'] = 'offset'; + $edit['options[group_info][group_items][2][value][min]'] = '+1 hour'; + $edit['options[group_info][group_items][2][value][max]'] = '+2 days'; + $edit['options[group_info][group_items][3][title]'] = 'between-date'; + $edit['options[group_info][group_items][3][operator]'] = 'between'; + $edit['options[group_info][group_items][3][value][min]'] = format_date(150000, 'custom', 'Y-m-d H:s'); + $edit['options[group_info][group_items][3][value][max]'] = format_date(250000, 'custom', 'Y-m-d H:s'); + + $this->drupalPostForm(NULL, $edit, t('Apply')); + + $this->drupalGet('admin/structure/views/nojs/handler/test_filter_date_between/default/filter/created'); + foreach ($edit as $name => $value) { + $this->assertFieldByName($name, $value); + if (strpos($name, '[value][type]')) { + $radio = $this->cssSelect('input[name="' . $name . '"][checked="checked"][type="radio"]'); + $this->assertEqual((string) $radio[0]['value'], $value); + } + } + + $this->drupalPostForm('admin/structure/views/view/test_filter_date_between', array(), t('Save')); + $this->assertConfigSchemaByName('views.view.test_filter_date_between'); + + // Test that the exposed filter works as expected. + $this->drupalGet('admin/structure/views/view/test_filter_date_between/edit'); + $this->drupalPostForm(NULL, array(), t('Update preview')); + $results = $this->cssSelect('.view-content .field-content'); + $this->assertEqual(count($results), 4); + $this->drupalPostForm(NULL, array('created' => '1'), t('Update preview')); + $results = $this->cssSelect('.view-content .field-content'); + $this->assertEqual(count($results), 1); + $this->assertEqual((string) $results[0], $this->nodes[3]->id()); + $this->drupalPostForm(NULL, array('created' => '2'), t('Update preview')); + $results = $this->cssSelect('.view-content .field-content'); + $this->assertEqual(count($results), 1); + $this->assertEqual((string) $results[0], $this->nodes[3]->id()); + $this->drupalPostForm(NULL, array('created' => '3'), t('Update preview')); + $results = $this->cssSelect('.view-content .field-content'); + $this->assertEqual(count($results), 1); + $this->assertEqual((string) $results[0], $this->nodes[1]->id()); + + // Change the filter to a single filter to test the schema when the operator + // is not exposed. + $this->drupalPostForm('admin/structure/views/nojs/handler/test_filter_date_between/default/filter/created', array(), t('Single filter')); + $edit = array(); + $edit['options[operator]'] = '>'; + $edit['options[value][type]'] = 'date'; + $edit['options[value][value]'] = format_date(350000, 'custom', 'Y-m-d H:s'); + $this->drupalPostForm(NULL, $edit, t('Apply')); + $this->drupalPostForm('admin/structure/views/view/test_filter_date_between', array(), t('Save')); + $this->assertConfigSchemaByName('views.view.test_filter_date_between'); + + // Test that the filter works as expected. + $this->drupalPostForm(NULL, array(), t('Update preview')); + $results = $this->cssSelect('.view-content .field-content'); + $this->assertEqual(count($results), 1); + $this->assertEqual((string) $results[0], $this->nodes[3]->id()); + $this->drupalPostForm(NULL, array('created' => format_date(250000, 'custom', 'Y-m-d H:s')), t('Update preview')); + $results = $this->cssSelect('.view-content .field-content'); + $this->assertEqual(count($results), 2); + $this->assertEqual((string) $results[0], $this->nodes[2]->id()); + $this->assertEqual((string) $results[1], $this->nodes[3]->id()); + } + }