You are here

function _nodeaccess_grants_form_submit in Nodeaccess 6

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

Private function to submit the per-node grants table. We use this so any user notifications aren't displayed when a userreference field causes the updating.

3 calls to _nodeaccess_grants_form_submit()
nodeaccess_delete_userreference in ./nodeaccess.module
Delete all userreference user grants from a node.
nodeaccess_grants_form_submit in ./nodeaccess.module
Submit function for nodeaccess_grants_form.
nodeaccess_insert_userreference in ./nodeaccess.module
Insert userreference grants from a node.

File

./nodeaccess.module, line 520

Code

function _nodeaccess_grants_form_submit($form, &$form_state) {
  $form_values =& $form_state['values'];
  global $user;
  $grants = array();
  $nid = $form_values['nid'];
  $node->nid = $nid;
  foreach (array(
    'uid',
    'rid',
  ) as $type) {
    $realm = 'nodeaccess_' . $type;
    if (is_array($form_values[$type])) {
      foreach ($form_values[$type] as $gid => $line) {
        $grant = array(
          'gid' => $gid,
          'realm' => $realm,
          'grant_view' => $line['grant_view'],
          'grant_update' => $line['grant_update'],
          'grant_delete' => $line['grant_delete'],
        );
        if ($grant['grant_view'] || $grant['grant_update'] || $grant['grant_delete']) {
          $grants[] = $grant;
        }
      }
    }
    node_access_write_grants($node, $grants, $realm);
  }

  // Save role and user grants to our own table.
  db_query("DELETE FROM {nodeaccess} WHERE nid = %d", $nid);
  foreach ($grants as $grant) {
    db_query("INSERT INTO {nodeaccess} (nid, gid, realm, grant_view, grant_update, grant_delete) VALUES (%d, %d, '%s', %d, %d, %d)", $nid, $grant['gid'], $grant['realm'], $grant['grant_view'], $grant['grant_update'], $grant['grant_delete']);
  }
}