You are here

function config_perms_admin_form in Custom Permissions 7.2

Same name and namespace in other branches
  1. 6.2 config_perms.admin.inc \config_perms_admin_form()

Administration form

1 string reference to 'config_perms_admin_form'
config_perms_menu in ./config_perms.module
Implements hook_menu().

File

./config_perms.admin.inc, line 11
Admin pages

Code

function config_perms_admin_form($form, &$form_state) {
  $form['perms'] = array(
    '#type' => 'fieldset',
    '#title' => t('Custom Permissions'),
    '#description' => '<p>' . t("Please note that the order in which permissions are granted are as follows:") . '</p>' . "<ul>" . "<li>" . t("User 1 still maintains full control") . "</li>\n" . "<li>" . t("Remove the permission 'Administer site configuration' from roles you wish to give access to only specified custom site configuration permissions") . "</li>\n" . "<li>" . t("Nothing will be available under Site building if 'display site building menu' is not checked") . "</li>\n" . "<li>" . t("Nothing will be available under Site configuration if 'display site configuration menu' is not checked") . "</li>\n" . "<li>" . t("Custom permissions <strong>cannot</strong> protect dynamic paths, which includes individual content, users, etc. (with system paths that receive an argument via the URL, such as node/1, node/2/edit, user/5, etc.)") . "</li>\n" . "<li>" . t("You can use * as wildcard for paths.") . "</ul>",
    '#collapsible' => 1,
    '#collapsed' => 0,
  );

  // Get perms.
  $perms = config_perms_perms(NULL, TRUE);
  $form['perms']['local'] = array(
    '#theme' => 'config_perms_form',
    '#tree' => TRUE,
    '#prefix' => '<div id="config_perms-wrapper">',
    '#suffix' => '</div>',
  );
  foreach ($perms as $key => $perm) {
    $form['perms']['local'][$key] = array(
      '#tree' => TRUE,
    );
    $form['perms']['local'][$key]['pid'] = array(
      '#type' => 'hidden',
      '#default_value' => isset($perm->pid) ? $perm->pid : NULL,
    );
    $form['perms']['local'][$key]['machine_name'] = array(
      '#type' => 'hidden',
      '#default_value' => $perm->machine_name,
    );
    $form['perms']['local'][$key]['status'] = array(
      '#type' => 'checkbox',
      '#default_value' => $perm->status,
    );
    $form['perms']['local'][$key]['remove'] = array(
      '#type' => 'checkbox',
      '#default_value' => 0,
    );
    $form['perms']['local'][$key]['name'] = array(
      '#type' => 'textfield',
      '#default_value' => $perm->name,
      '#size' => 30,
    );
    $form['perms']['local'][$key]['path'] = array(
      '#type' => 'textarea',
      '#default_value' => config_perms_parse_path($perm->path),
      '#size' => 50,
      '#rows' => 1,
    );
  }
  if (empty($form_state['num_new'])) {
    $form_state['num_new'] = 0;
  }
  for ($i = 0; $i < $form_state['num_new']; $i++) {
    $form['perms']['local'][$key + $i]['status'] = array(
      '#type' => 'checkbox',
      '#default_value' => $perm->status,
    );
    $form['perms']['local'][$key + $i]['remove'] = array(
      '#type' => 'checkbox',
      '#default_value' => 0,
    );
    $form['perms']['local'][$key + $i]['name'] = array(
      '#type' => 'textfield',
      '#default_value' => '',
      '#size' => 30,
    );
    $form['perms']['local'][$key + $i]['path'] = array(
      '#type' => 'textarea',
      '#default_value' => '',
      '#rows' => 2,
      '#size' => 50,
    );
  }
  $form['perms']['add']['status'] = array(
    '#name' => 'status',
    '#id' => 'edit-local-status',
    '#type' => 'submit',
    '#value' => t('Add permission'),
    '#submit' => array(
      'config_perms_admin_form_add_submit',
    ),
    '#ajax' => array(
      'callback' => 'config_perms_admin_form_add_callback',
      'wrapper' => 'config_perms-wrapper',
    ),
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
  );
  return $form;
}