diff --git a/core/modules/views/src/Tests/Handler/HandlerTest.php b/core/modules/views/src/Tests/Handler/HandlerTest.php index 4904baf..f084f90 100644 --- a/core/modules/views/src/Tests/Handler/HandlerTest.php +++ b/core/modules/views/src/Tests/Handler/HandlerTest.php @@ -69,26 +69,6 @@ protected function viewsData() { } /** - * @todo - * This should probably moved to a filter related test. - */ - function testFilterInOperatorUi() { - $admin_user = $this->drupalCreateUser(array('administer views', 'administer site configuration')); - $this->drupalLogin($admin_user); - - $path = 'admin/structure/views/nojs/handler/test_filter_in_operator_ui/default/filter/type'; - $this->drupalGet($path); - $this->assertFieldByName('options[expose][reduce]', FALSE); - - $edit = array( - 'options[expose][reduce]' => TRUE, - ); - $this->drupalPostForm($path, $edit, t('Apply')); - $this->drupalGet($path); - $this->assertFieldByName('options[expose][reduce]', TRUE); - } - - /** * Tests the breakString method. */ public function testBreakString() { diff --git a/core/modules/views_ui/js/views-admin.js b/core/modules/views_ui/js/views-admin.js index d0534cf..0349cca 100644 --- a/core/modules/views_ui/js/views-admin.js +++ b/core/modules/views_ui/js/views-admin.js @@ -551,10 +551,7 @@ * form button that should be clicked. */ clickRemoveGroupButton: function (event) { - // For some reason, here we only need to trigger .submit(), unlike for - // Drupal.viewsUi.RearrangeFilterHandler.prototype.clickAddGroupButton() - // where we had to trigger .mousedown() also. - this.table.find('#' + event.data.buttonId).trigger('submit'); + this.table.find('input#' + event.data.buttonId).trigger('mousedown').trigger('submit'); event.preventDefault(); }, @@ -567,7 +564,11 @@ var newRow; var titleRow; - var titleRows = $('tr.views-group-title'); + var titleRows = $('tr.views-group-title').once('duplicateGroupsOperator'); + + if (!titleRows.length) { + return this.operator; + } // Get rid of the explanatory text around the operator; its placement is // explanatory enough. @@ -579,14 +580,6 @@ // Move the operator to a new row just above the second group. titleRow = $('tr#views-group-title-2'); - this.operator.find('label').add('div.description').addClass('visually-hidden'); - this.operator.find('select').addClass('form-select'); - - // Keep a list of the operator dropdowns, so we can sync their behavior later. - dropdowns = this.operator; - - // Move the operator to a new row just above the second group. - titleRow = $('tr#views-group-title-2'); newRow = $(''); newRow.find('td').append(this.operator); newRow.insertBefore(titleRow); diff --git a/core/modules/views_ui/src/Form/Ajax/RearrangeFilter.php b/core/modules/views_ui/src/Form/Ajax/RearrangeFilter.php index 1b8e18d..7711c99 100644 --- a/core/modules/views_ui/src/Form/Ajax/RearrangeFilter.php +++ b/core/modules/views_ui/src/Form/Ajax/RearrangeFilter.php @@ -18,6 +18,13 @@ class RearrangeFilter extends ViewsFormBase { /** + * Constructs a new RearrangeFilter object. + */ + public function __construct($type = NULL) { + $this->setType($type); + } + + /** * {@inheritdoc} */ public function getFormKey() { @@ -128,6 +135,9 @@ public function buildForm(array $form, FormStateInterface $form_state) { 'class' => array('views-remove-group'), ), '#group' => $id, + '#ajax' => [ + 'path' => $this->getRequest()->getRequestUri(), + ] ); } $group_options[$id] = $id == 1 ? $this->t('Default group') : $this->t('Group @group', array('@group' => $id)); @@ -203,11 +213,15 @@ public function buildForm(array $form, FormStateInterface $form_state) { } $view->getStandardButtons($form, $form_state, 'views_ui_rearrange_filter_form'); + $form['actions']['add_group'] = array( '#type' => 'submit', '#value' => $this->t('Create new filter group'), '#id' => 'views-add-group', '#group' => 'add', + '#ajax' => [ + 'path' => $this->getRequest()->getRequestUri(), + ] ); return $form; @@ -259,16 +273,16 @@ public function submitForm(array &$form, FormStateInterface $form_state) { // If the #group property is set on the clicked button, that means we are // either adding or removing a group, not actually updating the filters. - $clicked_button = $form_state->get('clicked_button'); - if (!empty($clicked_button['#group'])) { - if ($clicked_button['#group'] == 'add') { + $triggering_element = $form_state->getTriggeringElement(); + if (!empty($triggering_element['#group'])) { + if ($triggering_element['#group'] == 'add') { // Add a new group $groups['groups'][] = 'AND'; } else { // Renumber groups above the removed one down. foreach (array_keys($groups['groups']) as $group_id) { - if ($group_id >= $clicked_button['#group']) { + if ($group_id >= $triggering_element['#group']) { $old_group = $group_id + 1; if (isset($groups['groups'][$old_group])) { $groups['groups'][$group_id] = $groups['groups'][$old_group]; diff --git a/core/modules/views_ui/src/Tests/FilterUITest.php b/core/modules/views_ui/src/Tests/FilterUITest.php new file mode 100644 index 0000000..f90900d --- /dev/null +++ b/core/modules/views_ui/src/Tests/FilterUITest.php @@ -0,0 +1,90 @@ +drupalCreateContentType(['type' => 'page']); + $this->enableViewsTestModule(); + } + + /** + * Tests that "Limit list to selected items" option is saved as expected when + * editing the Content type filter from the UI. + */ + public function testFilterInOperatorUi() { + $admin_user = $this->drupalCreateUser(array('administer views', 'administer site configuration')); + $this->drupalLogin($admin_user); + + $path = 'admin/structure/views/nojs/handler/test_filter_in_operator_ui/default/filter/type'; + $this->drupalGet($path); + $this->assertFieldByName('options[expose][reduce]', FALSE); + + $edit = [ + 'options[expose][reduce]' => TRUE + ]; + $this->drupalPostForm($path, $edit, t('Apply')); + $this->drupalGet($path); + $this->assertFieldByName('options[expose][reduce]', TRUE); + } + + /** + * Tests the filters from the UI. + */ + public function testFiltersUI() { + $admin_user = $this->drupalCreateUser(['administer views', 'administer site configuration']); + $this->drupalLogin($admin_user); + + // Tests that we can create a new filter group from UI. + $this->drupalGet('admin/structure/views/nojs/rearrange-filter/test_filter_groups/page'); + $this->assertNoRaw('Group 3', 'Group 3 has not been added yet.'); + + // Create 2 new groups. + $this->drupalPostForm(NULL, [], t('Create new filter group')); + $this->drupalPostForm(NULL, [], t('Create new filter group')); + + // Remove the new group 3. + $this->drupalPostForm(NULL, [], t('Remove group 3')); + + // Verify that the group 4 is now named as 3. + $this->assertRaw('Group 3', 'Group 3 still exists.'); + + // Remove the group 3 again. + $this->drupalPostForm(NULL, [], t('Remove group 3')); + + // Group 3 now does not exist. + $this->assertNoRaw('Group 3', 'Group 3 has not been added yet.'); + } + +}