You are here

function simple_access_form in Simple Access 7.2

Same name and namespace in other branches
  1. 8.3 simple_access.module \simple_access_form()
  2. 5.2 simple_access.module \simple_access_form()
  3. 5 simple_access.module \simple_access_form()
  4. 6.2 simple_access.module \simple_access_form()

Simple Access form.

2 calls to simple_access_form()
simple_access_form_node_form_alter in ./simple_access.module
Implements hook_form_FORM_ID_alter().
simple_access_form_node_type_form_alter in ./simple_access.module
Implements hook_form_FORM_ID_alter().

File

./simple_access.module, line 464
This module allows administrators to make nodes viewable by specific 'access groups'. Each access group can contain any number of roles. If a node is not assigned to any access groups, it will remain viewable by all users.

Code

function simple_access_form($node, $admin = FALSE) {

  // Get the array of checkbox options to use for each form element.
  // If the "Show groups even when user is not a member" setting is
  // enabled, or if the current user has 'administer nodes', let
  // them choose from any of the SA groups.
  $groups = simple_access_group_select();
  $profiles = simple_access_get_profiles_select();
  if (empty($groups) && empty($profiles) && !user_access('assign owner permissions')) {
    return;
  }
  $user_groups = is_array($node->simple_access) ? array_filter($node->simple_access, '_simple_access_filter_access') : array();
  $owner_priv = is_array($node->simple_access_owner) ? array_filter($node->simple_access_owner) : array();

  // Set up the outer fieldset.
  $form['simple_access'] = array(
    '#title' => t('Access'),
    '#type' => 'fieldset',
    '#collapsible' => TRUE,
    '#collapsed' => empty($user_groups) && empty($node->simple_access_profiles) && empty($owner_priv),
    '#access' => user_access('assign access to profiles') || user_access('assign access to nodes') || user_access('administer nodes'),
    '#attributes' => array(
      'class' => array(
        'simple-access-settings',
      ),
    ),
    '#weight' => 20,
    '#group' => 'additional_settings',
    '#attached' => array(
      'js' => array(
        drupal_get_path('module', 'simple_access') . '/simple_access.js',
      ),
    ),
  );
  if (!empty($profiles)) {
    $form['simple_access']['simple_access_profiles'] = array(
      '#type' => 'checkboxes',
      '#title' => t('Access profile'),
      '#default_value' => $node->simple_access_profiles,
      '#options' => $profiles,
      '#access' => user_access('assign access to profiles') || user_access('administer nodes'),
    );
  }
  if (!empty($groups) || user_access('assign owner permissions')) {
    $form['simple_access']['simple_access'] = array(
      '#tree' => TRUE,
      '#weight' => 5,
      '#access' => user_access('assign access to nodes') || user_access('administer nodes') || user_access('assign owner permissions'),
      '#theme' => 'simple_access_form',
      '#attached' => array(
        'css' => array(
          drupal_get_path('module', 'simple_access') . '/simple_access.css',
        ),
      ),
    );
    if ($admin) {
      $form['simple_access']['simple_access']['#admin'] = TRUE;
    }

    // Load the owner perminisions.
    $group = array(
      'name' => t('Owner permissions'),
      'access' => user_access('assign owner permissions') && isset($node->uid) && $node->uid,
    );
    $access = array(
      'owner' => $node->simple_access_owner,
    );
    $form['simple_access']['simple_access']['owner'] = simple_access_form_row('owner', $group, $access, $admin);
    $form['simple_access']['simple_access']['owner']['#parents'] = array(
      'simple_access_owner',
    );
    foreach ($groups as $gid => $group) {
      $form['simple_access']['simple_access'][$gid] = simple_access_form_row($gid, $group, $node->simple_access, $admin);
    }
  }
  return $form;
}