You are here

function nodeaccess_node_type in Nodeaccess 6

Same name and namespace in other branches
  1. 5 nodeaccess.module \nodeaccess_node_type()
  2. 6.2 nodeaccess.module \nodeaccess_node_type()

Implementation of hook_node_type().

File

./nodeaccess.module, line 783

Code

function nodeaccess_node_type($op, $info) {
  switch ($op) {
    case 'delete':

      // Node type is being deleted, delete its preferences.
      variable_del('nodeaccess_' . $info->type);
      $author_prefs = variable_get('nodeaccess_authors', array());
      unset($author_prefs[$info->type]);
      variable_set('nodeaccess_authors', $author_prefs);
      break;
    case 'update':

      // Node type has changed, move preferences to new type.
      if (!empty($info->old_type) && $info->old_type != $info->type) {
        $setting = variable_get('nodeaccess_' . $info->old_type, array());
        variable_del('nodeaccess_' . $info->old_type);
        variable_set('nodeaccess_' . $info->type, $setting);
        $author_prefs = variable_get('nodeaccess_authors', array());
        $author_prefs[$info->type] = array(
          'grant_view' => $author_prefs[$info->old_type]['grant_view'],
          'grant_update' => $author_prefs[$info->old_type]['grant_update'],
          'grant_delete' => $author_prefs[$info->old_type]['grant_delete'],
        );
        unset($author_prefs[$info->old_type]);
        variable_set('nodeaccess_authors', $author_prefs);
      }
      break;
    case 'insert':

      // New node type, default to view for authenticated and
      // anonymous users, and no special permissions for author.
      $grants[] = array(
        'gid' => 1,
        'realm' => 'nodeaccess_rid',
        'grant_view' => 1,
        'grant_update' => 0,
        'grant_delete' => 0,
      );
      $grants[] = array(
        'gid' => 2,
        'realm' => 'nodeaccess_rid',
        'grant_view' => 1,
        'grant_update' => 0,
        'grant_delete' => 0,
      );
      variable_set('nodeaccess_' . $info->type, $grants);
      $author_prefs = variable_get('nodeaccess_authors', array());
      $author_prefs[$info->type] = array(
        'grant_view' => 0,
        'grant_update' => 0,
        'grant_delete' => 0,
      );
      variable_set('nodeaccess_authors', $author_prefs);
      node_access_needs_rebuild(TRUE);
      break;
  }
}