You are here

function _nodeaccess_grants_form_submit in Nodeaccess 7

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

Private function to submit the per-node grants table.

Parameters

array $form:

array &$form_state:

4 calls to _nodeaccess_grants_form_submit()
nodeaccess_delete_user_reference 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_user_reference in ./nodeaccess.module
Insert userreference grants from a node.
nodeaccess_uuid_entity_uuid_save in nodeaccess_uuid/nodeaccess_uuid.module
Implements hook_entity_uuid_save().

File

./nodeaccess.module, line 479
Provide per node access control

Code

function _nodeaccess_grants_form_submit($form, &$form_state) {
  $form_values =& $form_state['values'];
  $grants = array();
  $nid = $form_values['nid'];
  $node = node_load($nid);
  foreach (array(
    'uid',
    'rid',
  ) as $type) {
    $realm = 'nodeaccess_' . $type;
    if (isset($form_values[$type]) && is_array($form_values[$type])) {
      foreach ($form_values[$type] as $gid => $line) {
        $grant = array(
          'gid' => $gid,
          'realm' => $realm,
          'grant_view' => empty($line['grant_view']) ? 0 : 1,
          'grant_update' => empty($line['grant_update']) ? 0 : 1,
          'grant_delete' => empty($line['grant_delete']) ? 0 : 1,
        );
        $grants[] = $grant;
      }
    }
  }
  nodeaccess_set_grants($node, $grants);
}