You are here

function book_access_ui_grants_form in Book access 6.2

Same name and namespace in other branches
  1. 7.2 book_access_ui.admin.inc \book_access_ui_grants_form()

Form builder for the book access configuration page.

See also

book_access_ui_user_add_submit()

book_access_ui_grants_form_submit()

theme_book_access_ui_grants_form()

1 string reference to 'book_access_ui_grants_form'
book_access_ui_menu in ./book_access_ui.module
Implements hook_menu().

File

./book_access_ui.admin.inc, line 17
Administration interface for the Book access module.

Code

function book_access_ui_grants_form($form_state, $node) {
  $bid = $node->book['bid'];
  $context = array(
    'bid' => $bid,
    'node' => clone $node,
  );
  $form = array(
    '#bid' => $bid,
    '#author' => $node->uid,
    '#rids' => array(),
    '#uids' => array(),
    '#tree' => TRUE,
  );
  $vars = new BookAccessVars();

  // Build the role access permissions for the book.
  $grants = BookAccess::getAuthorGrants($bid, $node->uid, $vars['book_access_default_roles_access']);
  $grants_copy = $grants;
  drupal_alter('book_access_author_grants', $grants, $context);
  if ($grants != $grants_copy) {
    _book_access_ui_permissions_warning();
  }
  $author = user_load($node->uid);
  if ($author) {
    $form['author']['name'] = array(
      '#value' => t('!author-href (author)', array(
        '!author-href' => theme('username', $author),
      )),
    );
  }
  else {
    $form['author']['name'] = array(
      '#value' => t('author'),
    );
  }
  $form['author']['grant_view'] = array(
    '#type' => 'checkbox',
    '#default_value' => !empty($grants['grant_view']),
  );
  $form['author']['grant_update'] = array(
    '#type' => 'checkbox',
    '#default_value' => !empty($grants['grant_update']),
  );
  $form['author']['grant_delete'] = array(
    '#type' => 'checkbox',
    '#default_value' => !empty($grants['grant_delete']),
  );
  $form['author']['grant_admin_access'] = array(
    '#type' => 'checkbox',
    '#default_value' => !empty($grants['grant_admin_access']),
  );
  $form['author']['grant_add_child'] = array(
    '#type' => 'checkbox',
    '#default_value' => !empty($grants['grant_add_child']),
  );
  $form['author']['grant_edit_outline'] = array(
    '#type' => 'checkbox',
    '#default_value' => !empty($grants['grant_edit_outline']),
  );
  $grants = BookAccess::getRoleGrants($bid, $roles, $vars['book_access_default_roles_access']);
  $grants_copy = $grants;
  $data =& $roles;
  $data['__drupal_alter_by_ref'] = array(
    &$grants,
  );
  drupal_alter('book_access_roles_grants', $data, $context);
  if ($grants != $grants_copy) {
    _book_access_ui_permissions_warning();
  }
  foreach ($roles as $rid => $name) {
    $form['#rids'][] = $rid;
    $form['roles']['names'][$rid] = array(
      '#value' => check_plain($name),
    );
    $form['roles']['grant_view'][$rid] = array(
      '#type' => 'checkbox',
      '#default_value' => !empty($grants['grant_view'][$rid]),
    );
    $form['roles']['grant_update'][$rid] = array(
      '#type' => 'checkbox',
      '#default_value' => !empty($grants['grant_update'][$rid]),
    );
    $form['roles']['grant_delete'][$rid] = array(
      '#type' => 'checkbox',
      '#default_value' => !empty($grants['grant_delete'][$rid]),
    );
    $form['roles']['grant_admin_access'][$rid] = array(
      '#type' => 'checkbox',
      '#default_value' => !empty($grants['grant_admin_access'][$rid]),
    );
    $form['roles']['grant_add_child'][$rid] = array(
      '#type' => 'checkbox',
      '#default_value' => !empty($grants['grant_add_child'][$rid]),
    );
    $form['roles']['grant_edit_outline'][$rid] = array(
      '#type' => 'checkbox',
      '#default_value' => !empty($grants['grant_edit_outline'][$rid]),
    );
  }
  $grants = BookAccess::getUserGrants($bid, $uids);
  $grants_copy = $grants;
  $data =& $uids;
  $data['__drupal_alter_by_ref'] = array(
    &$grants,
  );
  drupal_alter('book_access_users_grants', $data, $context);
  if ($grants != $grants_copy) {
    _book_access_ui_permissions_warning();
  }
  foreach ($uids as $uid) {
    $form['#uids'][] = $uid;
    $form['users']['grant_view'][$uid] = array(
      '#type' => 'checkbox',
      '#default_value' => !empty($grants['grant_view'][$uid]),
    );
    $form['users']['grant_update'][$uid] = array(
      '#type' => 'checkbox',
      '#default_value' => !empty($grants['grant_update'][$uid]),
    );
    $form['users']['grant_delete'][$uid] = array(
      '#type' => 'checkbox',
      '#default_value' => !empty($grants['grant_delete'][$uid]),
    );
    $form['users']['grant_admin_access'][$uid] = array(
      '#type' => 'checkbox',
      '#default_value' => !empty($grants['grant_admin_access'][$uid]),
    );
    $form['users']['grant_add_child'][$uid] = array(
      '#type' => 'checkbox',
      '#default_value' => !empty($grants['grant_add_child'][$uid]),
    );
    $form['users']['grant_edit_outline'][$uid] = array(
      '#type' => 'checkbox',
      '#default_value' => !empty($grants['grant_edit_outline'][$uid]),
    );
  }
  $form['user']['username'] = array(
    '#type' => 'textfield',
    '#size' => 20,
    '#autocomplete_path' => 'user/autocomplete',
  );
  $grants = array_filter($vars['book_access_default_users_access']);
  $form['user']['grant_view'] = array(
    '#type' => 'checkbox',
    '#default_value' => !empty($grants['grant_view']),
  );
  $form['user']['grant_update'] = array(
    '#type' => 'checkbox',
    '#default_value' => !empty($grants['grant_update']),
  );
  $form['user']['grant_delete'] = array(
    '#type' => 'checkbox',
    '#default_value' => !empty($grants['grant_delete']),
  );
  $form['user']['grant_admin_access'] = array(
    '#type' => 'checkbox',
    '#default_value' => !empty($grants['grant_admin_access']),
  );
  $form['user']['grant_add_child'] = array(
    '#type' => 'checkbox',
    '#default_value' => !empty($grants['grant_add_child']),
  );
  $form['user']['grant_edit_outline'] = array(
    '#type' => 'checkbox',
    '#default_value' => !empty($grants['grant_edit_outline']),
  );
  $form['user']['add_user'] = array(
    '#type' => 'submit',
    '#value' => t('Add user'),
    '#submit' => array(
      'book_access_ui_user_add_submit',
    ),
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save configuration'),
  );
  return $form;
}