diff --git a/core/modules/views_ui/js/views-admin.js b/core/modules/views_ui/js/views-admin.js index 7f217dc..ac9ff3d 100644 --- a/core/modules/views_ui/js/views-admin.js +++ b/core/modules/views_ui/js/views-admin.js @@ -547,10 +547,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(); }, @@ -561,7 +558,11 @@ duplicateGroupsOperator: function () { var dropdowns, newRow, 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. @@ -573,14 +574,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..a17d361 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' => array( + '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' => array( + '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];