1 node_access_example.module | node_access_example_node_update($node) |
Implements hook_node_update().
If the record in the node_access_example table already exists, we must update it; if it doesn't exist, we create it.
See also
nodeapi_example.module
Related topics
File
- modules/
examples/ node_access_example/ node_access_example.module, line 436 - Hook implementations for the Node Access Example module.
Code
function node_access_example_node_update($node) {
// Find out if there is already a node_access_example record.
$exists = db_query('SELECT nid FROM {node_access_example} WHERE nid = :nid',
array(':nid' => $node->nid))->fetchField();
if ($exists) {
// If there is already a record, update it with the new private value.
$num_updated = db_update('node_access_example')
->fields(array(
'nid' => $node->nid,
'private' => !empty($node->private) ? 1 : 0,
))
->condition('nid', $node->nid)
->execute();
backdrop_set_message(
t("Updated node @nid to set private=@private (@num nodes actually updated)",
array(
'@private' => $node->private,
'@num' => $num_updated,
'@nid' => $node->nid,
)
)
);
}
else {
// Otherwise, create a new record.
node_access_example_node_insert($node);
backdrop_set_message(t('Inserted new node_access nid=@nid, private=@private', array('@nid' => $node->nid, '@private' => $node->private)));
}
}