You are here

function find_perm_form in Util 7

Module settings form.

1 string reference to 'find_perm_form'
find_perm_menu in contribs/find_perm/find_perm.module
Implements hook_menu().

File

contribs/find_perm/find_perm.module, line 28
Find permission common to selected roles.

Code

function find_perm_form($form, &$form_state) {
  $form['#attached']['css'] = array(
    drupal_get_path('module', 'find_perm') . '/find_perm.css',
  );
  if (isset($form['#perms'])) {
    $perms = $form['#perms'];
  }
  else {
    $perms = module_invoke_all('permission');
    $form['#perms'] = $perms;
  }
  $roles = user_roles();
  asort($roles);
  $form['#roles'] = $roles;
  $admin = variable_get('user_admin_role', 0);
  $form['roles'] = array(
    '#type' => 'checkboxes',
    '#options' => $roles,
    '#title' => t('Roles'),
    '#default_value' => array(
      $admin => $admin,
    ),
  );
  $form['roles']['#description'] = t('Select the roles for which you seek a common permission.') . ' ' . t('Note, since the "@admin" role typically has all permissions, we cannot determine exclusive permissions without it.', array(
    '@admin' => $roles[$admin],
  ));
  if (isset($form_state['storage']['common'])) {
    $list = '<div class="common-permissions">' . theme('item_list', array(
      'items' => $form_state['storage']['common'],
      'title' => t('Permissions in common'),
    )) . '<div class="description">' . t('Items appearing <span class="exclusive">like this</span> are exclusive to the selected roles.') . '</div></div>';
    $form['common'] = array(
      '#type' => 'markup',
      '#markup' => $list,
    );
  }
  $form['actions'] = array(
    '#type' => 'actions',
  );
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Find common permissions'),
  );
  return $form;
}