diff --git a/core/modules/user/src/Form/UserPermissionsForm.php b/core/modules/user/src/Form/UserPermissionsForm.php index 9a1df99..d06474a 100644 --- a/core/modules/user/src/Form/UserPermissionsForm.php +++ b/core/modules/user/src/Form/UserPermissionsForm.php @@ -101,6 +101,26 @@ public function buildForm(array $form, FormStateInterface $form_state) { '#type' => 'system_compact_link', ); + $form['filters'] = array( + '#type' => 'container', + '#attributes' => array( + 'class' => array('table-filter', 'js-show'), + ), + ); + + $form['filters']['text'] = array( + '#type' => 'search', + '#title' => $this->t('Search'), + '#size' => 30, + '#placeholder' => $this->t('Enter permission name'), + '#attributes' => array( + 'class' => array('table-filter-text'), + 'data-table' => '#permissions', + 'autocomplete' => 'off', + 'title' => $this->t('Enter a part of the permission name to filter by.'), + ), + ); + $form['permissions'] = array( '#type' => 'table', '#header' => array($this->t('Permission')), @@ -140,7 +160,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { $options[$perm] = $perm_item['title']; $form['permissions'][$perm]['description'] = array( '#type' => 'inline_template', - '#template' => '
', + '#template' => ' ', '#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