diff --git a/core/modules/user/src/Form/UserPermissionsForm.php b/core/modules/user/src/Form/UserPermissionsForm.php index 9a1df99..4f5b8ef 100644 --- a/core/modules/user/src/Form/UserPermissionsForm.php +++ b/core/modules/user/src/Form/UserPermissionsForm.php @@ -140,7 +140,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { $options[$perm] = $perm_item['title']; $form['permissions'][$perm]['description'] = array( '#type' => 'inline_template', - '#template' => '
{{ title }}{% if description or warning %}
{% if warning %}{{ warning }} {% endif %}{{ description }}
{% endif %}
', + '#template' => '
{{ title }}{% if description or warning %}
{% if warning %}{{ warning }} {% endif %}{{ description }}
{% endif %}
', '#context' => array( 'title' => $perm_item['title'], ), diff --git a/core/modules/user/user.permissions.js b/core/modules/user/user.permissions.js index 415fc53..7d71cf6 100644 --- a/core/modules/user/user.permissions.js +++ b/core/modules/user/user.permissions.js @@ -49,6 +49,55 @@ // Re-insert the table into the DOM. $ancestor[method]($table); }); + + var $input = $('input.table-filter-text').once('table-filter-text'); + var $table = $($input.attr('data-table')); + var $rowsAndDetails, $rows, $details; + var searching = false; + + function filterPermissionList(e) { + var query = $(e.target).val().toLowerCase(); + + function showPermissionRow(index, row) { + var $row = $(row); + var $sources = $row.find('.table-filter-text-source'); + var textMatch = $sources.text().toLowerCase().indexOf(query) !== -1; + $row.closest('tr').toggle(textMatch); + } + // Search over all rows and packages. + $rowsAndDetails.show(); + + // Filter if the length of the query is at least 2 characters. + if (query.length >= 2) { + searching = true; + $rows.each(showPermissionRow); + + // Note that we first open all
to be able to use ':visible'. + // Mark the
elements that were closed before filtering, so + // they can be reclosed when filtering is removed. + $details.not('[open]').attr('data-drupal-system-state', 'forced-open'); + + // Hide the package
if they don't have any visible rows. + // Note that we first show() all
to be able to use ':visible'. + $details.attr('open', true).each(hidePackageDetails); + } + else if (searching) { + searching = false; + $rowsAndDetails.show(); + // Return
elements that had been closed before filtering + // to a closed state. + $details.filter('[data-drupal-system-state="forced-open"]') + .removeAttr('data-drupal-system-state') + .attr('open', false); + } + } + + if ($table.length) { + $rowsAndDetails = $table.find('tr, details'); + $rows = $table.find('tbody tr'); + $details = $rowsAndDetails.filter('.package-listing'); + $input.on('keyup', filterPermissionList); + } }, /**