You are here

function hook_publication_date_alter in Publication Date 8

Same name and namespace in other branches
  1. 7.2 publication_date.api.php \hook_publication_date_alter()
  2. 7 publication_date.api.php \hook_publication_date_alter()

Allows modules to alter the publication date before it is saved to the database on node update/insert.

Parameters

integer $published_at: A Unix timestamp representing the publication date to be altered. If no publication date has been set then $published_at should equal the defined constant PUBLICATION_DATE_DEFAULT.

object $node: The node object.

string $op: The node opperation being performed:

  • 'insert': a new node was created
  • 'update': an existing node was updated
1 invocation of hook_publication_date_alter()
publication_date_node_presave in ./publication_date.module
Implements hook_ENTITY_TYPE_presave().

File

./publication_date.api.php, line 23
API documentation for the Publication Date module.

Code

function hook_publication_date_alter(&$published_at, $node, $op) {

  // Check if the node is being published.
  if ($node->status == 1) {

    // If a future publication date was set, change it to the curret time.
    $published_at = $published_at > REQUEST_TIME ? REQUEST_TIME : $published_at;
  }
}