You are here

function nodeaccess_install in Nodeaccess 7

Same name and namespace in other branches
  1. 8.2 nodeaccess.install \nodeaccess_install()
  2. 8 nodeaccess.install \nodeaccess_install()
  3. 5 nodeaccess.install \nodeaccess_install()
  4. 6.2 nodeaccess.install \nodeaccess_install()
  5. 6 nodeaccess.install \nodeaccess_install()

Implements hook_install().

File

./nodeaccess.install, line 24
Install/uninstall functions for Nodeaccess.

Code

function nodeaccess_install() {

  // Set up default permissions to be view for authenticated and
  // anonymous users, and all permissions for author.
  $grants = array();
  $role_perms = user_role_permissions(array(
    1 => 1,
    2 => 2,
  ));
  $role_perms[1]['access content'] = isset($role_perms[1]['access content']) ? intval($role_perms[1]['access content']) : 0;
  $role_perms[2]['access content'] = isset($role_perms[2]['access content']) ? intval($role_perms[2]['access content']) : 0;

  // Anonymous user setting.
  $grants[] = array(
    'gid' => 1,
    'realm' => 'nodeaccess_rid',
    'grant_view' => $role_perms[1]['access content'],
  );

  // Authenticated user setting.
  $grants[] = array(
    'gid' => 2,
    'realm' => 'nodeaccess_rid',
    'grant_view' => $role_perms[2]['access content'],
  );
  $author_prefs = array();
  foreach (node_type_get_types() as $type => $name) {

    // We check the edit permissions for anonymous and authenticated users.
    $edit_perm = 'edit any ' . $type . ' content';
    $role_perms[1][$edit_perm] = isset($role_perms[1][$edit_perm]) ? intval($role_perms[1][$edit_perm]) : 0;
    $role_perms[2][$edit_perm] = isset($role_perms[2][$edit_perm]) ? intval($role_perms[2][$edit_perm]) : 0;
    $grants[0]['grant_update'] = $role_perms[1][$edit_perm];
    $grants[1]['grant_update'] = $role_perms[2][$edit_perm];

    // We check the delete permissions for anonymous and authenticated users.
    $delete_perm = 'delete any ' . $type . ' content';
    $role_perms[1][$delete_perm] = isset($role_perms[1][$delete_perm]) ? intval($role_perms[1][$delete_perm]) : 0;
    $role_perms[2][$delete_perm] = isset($role_perms[2][$delete_perm]) ? intval($role_perms[2][$delete_perm]) : 0;
    $grants[0]['grant_delete'] = $role_perms[1][$delete_perm];
    $grants[1]['grant_delete'] = $role_perms[2][$delete_perm];
    variable_set('nodeaccess_' . $type, $grants);
    $author_prefs[$type] = array(
      'grant_view' => 0,
      'grant_update' => 0,
      'grant_delete' => 0,
    );
  }
  variable_set('nodeaccess_authors', $author_prefs);

  // Set up all permissions to be editable by default.
  $grant_prefs = array(
    'view' => 1,
    'edit' => 1,
    'delete' => 1,
  );
  variable_set('nodeaccess-grants', $grant_prefs);
}