From d1db57412d6392f26453c4a8ee5faf1eb228d0a6 Mon Sep 17 00:00:00 2001 From: "tim.plunkett" <tim.plunkett@241634.no-reply.drupal.org> Date: Sat, 18 Aug 2012 23:04:31 +0200 Subject: [PATCH] Issue #1719496 by dagmar: Fixed Filter cannot be configured after certain conditions. --- .../Plugin/views/filter/FilterPluginBase.php | 20 ++++++------ lib/Drupal/views/Tests/ExposedFormTest.php | 31 +++++++++++++++++++ 2 files changed, 42 insertions(+), 9 deletions(-) diff --git a/lib/Drupal/views/Plugin/views/filter/FilterPluginBase.php b/lib/Drupal/views/Plugin/views/filter/FilterPluginBase.php index ab230edfe417..b22a3888ad6e 100644 --- a/lib/Drupal/views/Plugin/views/filter/FilterPluginBase.php +++ b/lib/Drupal/views/Plugin/views/filter/FilterPluginBase.php @@ -184,7 +184,7 @@ function can_build_group() { * Returns TRUE if the exposed filter works like a grouped filter. */ function is_a_group() { - return !empty($this->options['is_grouped']); + return $this->is_exposed() && !empty($this->options['is_grouped']); } /** @@ -597,16 +597,18 @@ function expose_validate($form, &$form_state) { * Validate the build group options form. */ function build_group_validate($form, &$form_state) { - if (empty($form_state['values']['options']['group_info']['identifier'])) { - form_error($form['group_info']['identifier'], t('The identifier is required if the filter is exposed.')); - } + if (!empty($form_state['values']['options']['group_info'])) { + if (empty($form_state['values']['options']['group_info']['identifier'])) { + form_error($form['group_info']['identifier'], t('The identifier is required if the filter is exposed.')); + } - if (!empty($form_state['values']['options']['group_info']['identifier']) && $form_state['values']['options']['group_info']['identifier'] == 'value') { - form_error($form['group_info']['identifier'], t('This identifier is not allowed.')); - } + if (!empty($form_state['values']['options']['group_info']['identifier']) && $form_state['values']['options']['group_info']['identifier'] == 'value') { + form_error($form['group_info']['identifier'], t('This identifier is not allowed.')); + } - if (!$this->view->display_handler->is_identifier_unique($form_state['id'], $form_state['values']['options']['group_info']['identifier'])) { - form_error($form['group_info']['identifier'], t('This identifier is used by another handler.')); + if (!$this->view->display_handler->is_identifier_unique($form_state['id'], $form_state['values']['options']['group_info']['identifier'])) { + form_error($form['group_info']['identifier'], t('This identifier is used by another handler.')); + } } if (!empty($form_state['values']['options']['group_info']['group_items'])) { diff --git a/lib/Drupal/views/Tests/ExposedFormTest.php b/lib/Drupal/views/Tests/ExposedFormTest.php index 4f5082e37a16..8207c50d6edc 100644 --- a/lib/Drupal/views/Tests/ExposedFormTest.php +++ b/lib/Drupal/views/Tests/ExposedFormTest.php @@ -65,6 +65,13 @@ function testExposedAdminUi() { // Be sure that the button is called exposed. $this->helperButtonHasLabel('edit-options-expose-button-button', t('Expose filter')); + // The first time the filter UI is displayed, the operator and the + // value forms should be shown. + $this->assertFieldById('edit-options-operator-in', '', 'Operator In exists'); + $this->assertFieldById('edit-options-operator-not-in', '', 'Operator Not In exists'); + $this->assertFieldById('edit-options-value-page', '', 'Checkbox for Page exists'); + $this->assertFieldById('edit-options-value-article', '', 'Checkbox for Article exists'); + // Click the Expose filter button. $this->drupalPost('admin/structure/views/nojs/config-item/test_exposed_admin_ui/default/filter/type', $edit, t('Expose filter')); // Check the label of the expose button. @@ -72,6 +79,12 @@ function testExposedAdminUi() { // Check the label of the grouped exposed button $this->helperButtonHasLabel('edit-options-group-button-button', t('Grouped filters')); + // After exposing the filter, Operator and Value should be still here. + $this->assertFieldById('edit-options-operator-in', '', 'Operator In exists'); + $this->assertFieldById('edit-options-operator-not-in', '', 'Operator Not In exists'); + $this->assertFieldById('edit-options-value-page', '', 'Checkbox for Page exists'); + $this->assertFieldById('edit-options-value-article', '', 'Checkbox for Article exists'); + // Check the validations of the filter handler. $edit = array(); $edit['options[expose][identifier]'] = ''; @@ -91,6 +104,14 @@ function testExposedAdminUi() { // Click the Grouped Filters button. $this->drupalGet('admin/structure/views/nojs/config-item/test_exposed_admin_ui/default/filter/type'); $this->drupalPost(NULL, array(), t('Grouped filters')); + + // After click on 'Grouped Filters', the standard operator and value should + // not be displayed. + $this->assertNoFieldById('edit-options-operator-in', '', 'Operator In not exists'); + $this->assertNoFieldById('edit-options-operator-not-in', '', 'Operator Not In not exists'); + $this->assertNoFieldById('edit-options-value-page', '', 'Checkbox for Page not exists'); + $this->assertNoFieldById('edit-options-value-article', '', 'Checkbox for Article not exists'); + // Check that after click on 'Grouped Filters', a new button is shown to // add more items to the list. $this->helperButtonHasLabel('edit-options-group-info-add-group', t('Add another item')); @@ -125,6 +146,16 @@ function testExposedAdminUi() { $this->drupalPost(NULL, $edit, t('Apply')); $this->assertRaw(t('The title is required if value for this item is defined.'), t('Group items should have a title')); + // Un-expose the filter. + $this->drupalGet('admin/structure/views/nojs/config-item/test_exposed_admin_ui/default/filter/type'); + $this->drupalPost(NULL, array(), t('Hide filter')); + + // After Un-exposing the filter, Operator and Value should be shown again. + $this->assertFieldById('edit-options-operator-in', '', 'Operator In exists after hide filter'); + $this->assertFieldById('edit-options-operator-not-in', '', 'Operator Not In exists after hide filter'); + $this->assertFieldById('edit-options-value-page', '', 'Checkbox for Page exists after hide filter'); + $this->assertFieldById('edit-options-value-article', '', 'Checkbox for Article exists after hide filter'); + // Click the Expose sort button. $edit = array(); $this->drupalPost('admin/structure/views/nojs/config-item/test_exposed_admin_ui/default/sort/created', $edit, t('Expose sort')); -- GitLab