diff --git a/core/modules/block/js/block.admin.js b/core/modules/block/js/block.admin.js index eaee165..f929521 100644 --- a/core/modules/block/js/block.admin.js +++ b/core/modules/block/js/block.admin.js @@ -10,16 +10,15 @@ /** * Filters the block list by a text input search string. * - * The label input will have the selector `input.block-filter-text`. - * The category input will have the selector `input.block-filter-text`. + * The text input will have the selector `input.block-filter-text`. * * The target element to do searching in will be in the selector * `input.block-filter-text[data-element]` * - * The text source where the label should be found will have the selector + * The text source where the label text should be found will have the selector * `.block-filter-text-source` * - * The text source where the category should be found will have the selector + * The text source where the category text should be found will have the selector * `.block-filter-category-source` * * @type {Drupal~behavior} @@ -29,9 +28,8 @@ */ Drupal.behaviors.blockFilterByText = { attach: function (context, settings) { - var $input_label = $('input.block-filter-text').once('block-filter-text'); - var $input_category = $('input.block-filter-category').once('block-filter-text'); - var $table = $($input_label.attr('data-element')); + var $input = $('input.block-filter-text').once('block-filter-text'); + var $table = $($input.attr('data-element')); var $filter_rows; /** @@ -41,8 +39,7 @@ * The jQuery event for the keyup event that triggered the filter. */ function filterBlockList(e) { - var query_label = $($input_label).val().toLowerCase(); - var query_category = $($input_category).val().toLowerCase(); + var query = $(e.target).val().toLowerCase(); /** * Shows or hides the block entry based on the query. @@ -55,19 +52,19 @@ function toggleBlockEntry(index, label) { var $label = $(label); var $row = $label.parent().parent(); - var labelMatch = query_label.length > 0 ? $label.text().toLowerCase().indexOf(query_label) !== -1 : true; + var labelMatch = $label.text().toLowerCase().indexOf(query) !== -1; + var categoryMatch = false; - var categoryMatch = true; - if (query_category.length > 0) { + if (!labelMatch) { var $category = $label.parent().parent().find('div.block-filter-category-source'); - categoryMatch = $category.text().toLowerCase().indexOf(query_category) !== -1; + categoryMatch = $category.text().toLowerCase().indexOf(query) !== -1; } - // Show if both match. - $row.toggle(labelMatch && categoryMatch); + + $row.toggle(labelMatch || categoryMatch); } - // Filter if the length of either query is at least 2 characters. - if (query_label.length >= 2 || query_category.length >= 2) { + // Filter if the length of the query is at least 2 characters. + if (query.length >= 2) { $filter_rows.each(toggleBlockEntry); } else { @@ -79,8 +76,7 @@ if ($table.length) { $filter_rows = $table.find('div.block-filter-text-source'); - $input_label.on('keyup', filterBlockList); - $input_category.on('keyup', filterBlockList); + $input.on('keyup', filterBlockList); } } }; diff --git a/core/modules/block/src/Controller/BlockLibraryController.php b/core/modules/block/src/Controller/BlockLibraryController.php index 75fe108..c8a9cdf 100644 --- a/core/modules/block/src/Controller/BlockLibraryController.php +++ b/core/modules/block/src/Controller/BlockLibraryController.php @@ -125,7 +125,6 @@ public function listBlocks(Request $request, $theme) { 'category' => $plugin_definition['category'], ], ]; - $links['add'] = [ 'title' => $this->t('Place block'), 'url' => Url::fromRoute('block.admin_add', ['plugin_id' => $plugin_id, 'theme' => $theme]), @@ -157,24 +156,11 @@ public function listBlocks(Request $request, $theme) { '#title' => $this->t('Filter'), '#title_display' => 'invisible', '#size' => 30, - '#placeholder' => $this->t('Filter by block name'), + '#placeholder' => $this->t('Filter by block name or category'), '#attributes' => [ 'class' => ['block-filter-text'], 'data-element' => '.block-add-table', - 'title' => $this->t('Enter a part of the block name to filter by.'), - ], - ]; - - $build['filter_by_category'] = [ - '#type' => 'search', - '#title' => $this->t('Filter'), - '#title_display' => 'invisible', - '#size' => 30, - '#placeholder' => $this->t('Filter by block category'), - '#attributes' => [ - 'class' => ['block-filter-category'], - 'data-element' => '.block-add-table', - 'title' => $this->t('Enter a part of the block category to filter by.'), + 'title' => $this->t('Enter a part of the block name or category to filter by.'), ], ];