You are here

function content_access_page in Content Access 7

Same name and namespace in other branches
  1. 5 content_access.module \content_access_page()
  2. 6 content_access.admin.inc \content_access_page()

Per node settings page.

1 string reference to 'content_access_page'
content_access_menu in ./content_access.module
Implements hook_menu().

File

./content_access.admin.inc, line 15
Content access administration UI.

Code

function content_access_page($form, &$form_state, $node) {
  drupal_set_title(t('Access control for @title', array(
    '@title' => $node->title,
  )));
  foreach (_content_access_get_operations() as $op => $label) {
    $defaults[$op] = content_access_per_node_setting($op, $node);
  }

  // Get roles form
  content_access_role_based_form($form, $defaults, $node->type);

  // Add an after_build handler that disables checkboxes, which are enforced by permissions.
  $form['per_role']['#after_build'] = array(
    'content_access_force_permissions',
  );

  // ACL form
  if (module_exists('acl')) {

    // This is disabled when there is no node passed.
    $form['acl'] = array(
      '#type' => 'fieldset',
      '#title' => t('User access control lists'),
      '#description' => t('These settings allow you to grant access to specific users.'),
      '#collapsible' => TRUE,
      '#tree' => TRUE,
    );
    foreach (array(
      'view',
      'update',
      'delete',
    ) as $op) {
      $acl_id = content_access_get_acl_id($node, $op);
      acl_node_add_acl($node->nid, $acl_id, (int) ($op == 'view'), (int) ($op == 'update'), (int) ($op == 'delete'), content_access_get_settings('priority', $node->type));
      $form['acl'][$op] = acl_edit_form($form_state, $acl_id, t('Grant !op access', array(
        '!op' => $op,
      )));
      $form['acl'][$op]['#collapsed'] = !isset($_POST['acl_' . $acl_id]) && !unserialize($form['acl'][$op]['user_list']['#default_value']);
    }
  }
  $form_state['node'] = $node;
  $form['reset'] = array(
    '#type' => 'submit',
    '#value' => t('Reset to defaults'),
    '#weight' => 10,
    '#submit' => array(
      'content_access_page_reset',
    ),
    '#access' => !empty(content_access_get_per_node_settings($node)),
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Submit'),
    '#weight' => 10,
  );

  // @todo not true anymore?
  // http://drupal.org/update/modules/6/7#hook_node_access_records
  if (!$node->status) {
    drupal_set_message(t("Warning: Your content is not published, so this settings are not taken into account as long as the content remains unpublished."), 'error');
  }
  return $form;
}