You are here

function workbench_access_node_insert in Workbench Access 7

Implements hook_node_insert().

1 call to workbench_access_node_insert()
workbench_access_node_update in ./workbench_access.module
Implements hook_node_update().

File

./workbench_access.module, line 630
Workbench Access module file.

Code

function workbench_access_node_insert($node) {

  // Clear the old records for this node.
  workbench_access_node_delete($node);

  // Make sure we have processed new data.
  workbench_access_node_presave($node);

  // If nothing to set, we are done.
  if (empty($node->workbench_access)) {
    return;
  }

  // Ensure we have an array, as the form can allow multiple selects or single.
  if (!is_array($node->workbench_access)) {
    $node->workbench_access = array(
      $node->workbench_access,
    );
  }

  // Load the active tree to get the access scheme data and validate that
  // the selections are actually present.
  $active = workbench_access_get_active_tree();
  foreach ($node->workbench_access as $id) {

    // Prevent false records from being saved accidentally.
    if (isset($active['active'][$id])) {
      $record = array(
        'nid' => $node->nid,
        'access_id' => $id,
        'access_scheme' => $active['access_scheme']['access_scheme'],
      );
      drupal_write_record('workbench_access_node', $record);
    }
  }

  // Clear static caches for tokens.
  drupal_static_reset('_workbench_access_get_node_section_names');
}