You are here

function apps_admin_permissions in Apps 7

Copy of user_admin_permissions() but for specific permissions.

1 string reference to 'apps_admin_permissions'
apps_app_config_page in ./apps.pages.inc
Callback for app config page

File

./apps.pages.inc, line 187
The page callbacks for the Apps module.

Code

function apps_admin_permissions($form, $form_state, $app) {
  $form['#app'] = $app;
  $form['#theme'] = 'user_admin_permissions';

  // Retrieve role names for columns.
  $role_names = user_roles();

  // Fetch permissions for all roles or the one selected role.
  $role_permissions = user_role_permissions($role_names);

  // Store $role_names for use when saving the data.
  $form['role_names'] = array(
    '#type' => 'value',
    '#value' => $role_names,
  );
  $permissions = module_invoke_all('permission');
  $hide_descriptions = system_admin_compact_mode();
  $options = array();
  foreach ($app['permissions'] as $perm => $default_roles) {
    if (!empty($permissions[$perm])) {
      $perm_item = $permissions[$perm];

      // Fill in default values for the permission.
      $perm_item += array(
        'description' => '',
        'restrict access' => FALSE,
        'warning' => !empty($perm_item['restrict access']) ? t('Warning: Give to trusted roles only; this permission has security implications.') : '',
      );
      $options[$perm] = '';
      $form['permission'][$perm] = array(
        '#type' => 'item',
        '#markup' => $perm_item['title'],
        '#description' => theme('user_permission_description', array(
          'permission_item' => $perm_item,
          'hide' => $hide_descriptions,
        )),
      );
      foreach ($role_names as $rid => $name) {

        // Builds arrays for checked boxes for each role
        if (isset($role_permissions[$rid][$perm])) {
          $status[$rid][] = $perm;
        }
      }
    }
  }

  // Have to build checkboxes here after checkbox arrays are built
  foreach ($role_names as $rid => $name) {
    $form['checkboxes'][$rid] = array(
      '#type' => 'checkboxes',
      '#options' => $options,
      '#default_value' => isset($status[$rid]) ? $status[$rid] : array(),
      '#attributes' => array(
        'class' => array(
          'rid-' . $rid,
        ),
      ),
    );
    $form['role_names'][$rid] = array(
      '#markup' => check_plain($name),
      '#tree' => TRUE,
    );
  }
  $form['actions'] = array(
    '#type' => 'actions',
  );
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save permissions'),
    '#submit' => array(
      'user_admin_permissions_submit',
    ),
  );
  $form['actions']['revert'] = array(
    '#type' => 'submit',
    '#value' => t('Revert to defaults'),
    '#submit' => array(
      'apps_admin_permissions_revert_submit',
    ),
  );
  $form['#attached']['js'][] = drupal_get_path('module', 'user') . '/user.permissions.js';
  return $form;
}