function _publication_date_set_date in Publication Date 7.2
Same name and namespace in other branches
- 7 publication_date.module \_publication_date_set_date()
Worker function to save the published date to the database.
Parameters
object $node: The node object.
string $op: The node operation being performed:
- 'insert': A new node was created.
- 'update': An existing node was updated.
See also
2 calls to _publication_date_set_date()
- publication_date_node_insert in ./
publication_date.module - Implements hook_node_insert().
- publication_date_node_update in ./
publication_date.module - Implements hook_node_update().
File
- ./
publication_date.module, line 87 - Add a field to nodes containing the publication date.
Code
function _publication_date_set_date($node, $op = '') {
// If a publication date has already been set then retain it.
if (!empty($node->published_at)) {
$published_at = $node->published_at;
}
elseif ($node->status == 1) {
$published_at = REQUEST_TIME;
}
else {
$published_at = NULL;
}
// Allow other modules to alter the publication date before it is saved.
drupal_alter('publication_date', $published_at, $node, $op);
// Update the node object.
$node->published_at = $published_at;
// Save the publication date to the database.
db_merge('publication_date')
->key(array(
'nid' => $node->nid,
))
->fields(array(
'published_at' => $published_at,
))
->execute();
}