You are here

function publication_date_node_load in Publication Date 7.2

Same name and namespace in other branches
  1. 7 publication_date.module \publication_date_node_load()

Implements hook_node_load().

For each node we set four properties...

  • published_at: Equals the publication date in Epoc time, if one has been set, or NULL otherwise.
  • published_at_or_now: Equals published_at if a publication date has been set, or the current REQUEST_TIME if it hasn't.
  • published_at_or_changed: Equals published_at if a publication date has been set, or the node's changed timestamp if it hasn't.
  • published_at_or_created: Equals published_at if a publication date has been set, or the node's created timestamp if it hasn't.

File

./publication_date.module, line 30
Add a field to nodes containing the publication date.

Code

function publication_date_node_load($nodes, $types) {
  foreach ($nodes as $node) {

    // Get the publication date from the database and set node properties.
    if ($published_at = _publication_date_get_date($node->nid)) {
      $node->published_at = $published_at;
      $node->published_at_or_now = $published_at;
      $node->published_at_or_changed = $published_at;
      $node->published_at_or_created = $published_at;
    }
    else {
      $node->published_at = NULL;
      $node->published_at_or_now = REQUEST_TIME;
      $node->published_at_or_changed = $node->changed;
      $node->published_at_or_created = $node->created;
    }
  }
}