You are here

function _publication_date_set_date in Publication Date 7

Same name and namespace in other branches
  1. 7.2 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 opperation being performed:

  • 'insert': a new node was created
  • 'update': an existing node was updated

See also

hook_node_insert()

hook_node_update()

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 69
Add a field to nodes containing the publication date.

Code

function _publication_date_set_date($node, $op = '') {

  // Set a default publication date value.
  $published_at = empty($node->published_at) ? 0 : $node->published_at;

  // If no publication date has been set and the node is published then use
  // REQUEST_TIME. Otherwise, use the default publication date.
  $published_at = $published_at == 0 && $node->status == 1 ? REQUEST_TIME : $published_at;

  // 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();
}