diff --git a/core/modules/views_ui/js/views-admin.es6.js b/core/modules/views_ui/js/views-admin.es6.js index 069416693485fe75e3fa5afb3c8e6ef93ed18ec4..afc8aa30d71e952d2d9ebe1b6152ddc39f5d1463 100644 --- a/core/modules/views_ui/js/views-admin.es6.js +++ b/core/modules/views_ui/js/views-admin.es6.js @@ -629,38 +629,6 @@ }, }; - /** - * Rearranges the filters. - * - * @type {Drupal~behavior} - * - * @prop {Drupal~behaviorAttach} attach - * Attach handlers to make it possible to rearrange the filters in the form - * in question. - * @see Drupal.viewsUi.RearrangeFilterHandler - */ - Drupal.behaviors.viewsUiRearrangeFilter = { - attach(context) { - // Only act on the rearrange filter form. - if ( - typeof Drupal.tableDrag === 'undefined' || - typeof Drupal.tableDrag['views-rearrange-filters'] === 'undefined' - ) { - return; - } - const $context = $(context); - const $table = $context - .find('#views-rearrange-filters') - .once('views-rearrange-filters'); - const $operator = $context - .find('.js-form-item-filter-groups-operator') - .once('views-rearrange-filters'); - if ($table.length) { - new Drupal.viewsUi.RearrangeFilterHandler($table, $operator); - } - }, - }; - /** * Improve the UI of the rearrange filters dialog box. * @@ -1322,4 +1290,36 @@ }); }, }; + + /** + * Rearranges the filters. + * + * @type {Drupal~behavior} + * + * @prop {Drupal~behaviorAttach} attach + * Attach handlers to make it possible to rearrange the filters in the form + * in question. + * @see Drupal.viewsUi.RearrangeFilterHandler + */ + Drupal.behaviors.viewsUiRearrangeFilter = { + attach(context) { + // Only act on the rearrange filter form. + if ( + typeof Drupal.tableDrag === 'undefined' || + typeof Drupal.tableDrag['views-rearrange-filters'] === 'undefined' + ) { + return; + } + const $context = $(context); + const $table = $context + .find('#views-rearrange-filters') + .once('views-rearrange-filters'); + const $operator = $context + .find('.js-form-item-filter-groups-operator') + .once('views-rearrange-filters'); + if ($table.length) { + new Drupal.viewsUi.RearrangeFilterHandler($table, $operator); + } + }, + }; })(jQuery, Drupal, drupalSettings); diff --git a/core/modules/views_ui/js/views-admin.js b/core/modules/views_ui/js/views-admin.js index a37acfef57a7721c6296f43249d01c9490af1849..0bcca18d2398b17b5bff3bf67c5fd9dea6f0e486 100644 --- a/core/modules/views_ui/js/views-admin.js +++ b/core/modules/views_ui/js/views-admin.js @@ -296,21 +296,6 @@ } } }; - Drupal.behaviors.viewsUiRearrangeFilter = { - attach: function attach(context) { - if (typeof Drupal.tableDrag === 'undefined' || typeof Drupal.tableDrag['views-rearrange-filters'] === 'undefined') { - return; - } - - var $context = $(context); - var $table = $context.find('#views-rearrange-filters').once('views-rearrange-filters'); - var $operator = $context.find('.js-form-item-filter-groups-operator').once('views-rearrange-filters'); - - if ($table.length) { - new Drupal.viewsUi.RearrangeFilterHandler($table, $operator); - } - } - }; Drupal.viewsUi.RearrangeFilterHandler = function ($table, $operator) { this.table = $table; @@ -602,4 +587,19 @@ }); } }; + Drupal.behaviors.viewsUiRearrangeFilter = { + attach: function attach(context) { + if (typeof Drupal.tableDrag === 'undefined' || typeof Drupal.tableDrag['views-rearrange-filters'] === 'undefined') { + return; + } + + var $context = $(context); + var $table = $context.find('#views-rearrange-filters').once('views-rearrange-filters'); + var $operator = $context.find('.js-form-item-filter-groups-operator').once('views-rearrange-filters'); + + if ($table.length) { + new Drupal.viewsUi.RearrangeFilterHandler($table, $operator); + } + } + }; })(jQuery, Drupal, drupalSettings); \ No newline at end of file diff --git a/core/modules/views_ui/tests/src/FunctionalJavascript/FilterCriteriaTest.php b/core/modules/views_ui/tests/src/FunctionalJavascript/FilterCriteriaTest.php index 190de4fb4126cfa686f8ec8ccf0ed7d3316100fe..857dcf61f0145f448e69575c6a71ff833b4047e7 100644 --- a/core/modules/views_ui/tests/src/FunctionalJavascript/FilterCriteriaTest.php +++ b/core/modules/views_ui/tests/src/FunctionalJavascript/FilterCriteriaTest.php @@ -125,6 +125,54 @@ public function testFilterCriteriaDialog() { $this->assertFalse($remove_link->isVisible(), 'Remove group should be invisible after drag.'); } + /** + * Tests operator labels. + */ + public function testOperatorLabels() { + // Open the "Frontpage" view. + $this->drupalGet('admin/structure/views/view/frontpage'); + $session = $this->getSession(); + $page = $session->getPage(); + + // Open the "Rearrange filter criteria" dialog. + $this->openFilterDialog(); + + // Get the last filter on the list. + $row = $page->findAll('css', '.draggable'); + $row_count = count($row); + $last_row = array_pop($row); + $penultimate_row = array_pop($row); + + // Drag the last row before the penultimate row. + $drag_handle = $last_row->find('css', '.tabledrag-handle'); + $drag_handle->dragTo($penultimate_row); + + // Assert there are valid number of visible operator labels. + $operator_label = $page->findAll('css', '.views-operator-label'); + $this->assertEquals($row_count - 1, count($operator_label), 'There are valid number of operator labels after drag.'); + + // Get the last filter on the rearranged list. + $row = $page->findAll('css', '.draggable'); + $last_row = array_pop($row); + $penultimate_row = array_pop($row); + + // Assert the operator label in the penultimate row is shown. + $operator_label = $penultimate_row->find('css', '.views-operator-label'); + $this->assertTrue($operator_label->isVisible(), 'Operator label in the penultimate row is not visible after drag.'); + + // Assert the operator label in the last row is not shown. + $operator_label = $last_row->find('css', '.views-operator-label'); + $this->assertNull($operator_label, 'Operator label in the last row is not visible after drag.'); + + // Remove the last filter. + $remove_link = $last_row->find('css', '.views-remove-link'); + $remove_link->click(); + + // The current last filter shouldn't have the operator label. + $operator_label = $penultimate_row->find('css', '.views-operator-label'); + $this->assertNull($operator_label, 'The penultimate filter has no operator label after the last filter is removed.'); + } + /** * Uses the 'And/Or Rearrange' link for filters to open a dialog. */