permissions_filter.module 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. use Drupal\Core\Form\FormStateInterface;
  3. use Drupal\Core\Routing\RouteMatchInterface;
  4. /**
  5. * Implements hook_help().
  6. */
  7. function permissions_filter_help($route_name, RouteMatchInterface $route_match) {
  8. switch ($route_name) {
  9. // Main module help for the permissions_filter module.
  10. case 'help.page.permissions_filter':
  11. $output = '';
  12. $output .= '<h3>' . t('About') . '</h3>';
  13. $output .= '<p>' . t('Create a filter for permission page.') . '</p>';
  14. return $output;
  15. default:
  16. }
  17. }
  18. /**
  19. * Implements hook_form_alter() on behalf of permissions_filter.module.
  20. */
  21. function permissions_filter_form_alter(&$form, FormStateInterface $form_state, $form_id) {
  22. if ($form_id == 'user_admin_permissions') {
  23. $form['filters'] = array(
  24. '#type' => 'container',
  25. '#attributes' => array(
  26. 'class' => array('table-filter', 'js-show'),
  27. ),
  28. '#weight' => -1,
  29. );
  30. $form['filters']['search_permission'] = array(
  31. '#type' => 'search',
  32. '#title' => t('Enter a part of the Permission name or description'),
  33. '#title_display' => 'invisible',
  34. '#size' => 30,
  35. '#placeholder' => t('Filter by name or description'),
  36. '#description' => t('Enter a part of the permission'),
  37. '#attributes' => array(
  38. 'class' => array('table-filter-text'),
  39. 'data-table' => '#user-admin-permissions',
  40. 'autocomplete' => 'off',
  41. ),
  42. );
  43. $form['#attached']['library'][] = 'permissions_filter/permissions_js';
  44. }
  45. }