Created
August 17, 2016 00:55
-
-
Save Unifex/4dc75207bbe5a1e6bd6c8870762f96ff to your computer and use it in GitHub Desktop.
Drupal 7: Find when a node is first published. This uses workbench moderation.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Implements hook_preprocess_node(). | |
*/ | |
function my_module_preprocess_node(&$variables) { | |
$node = $variables['node']; | |
// First published. | |
// This query uses workbench moderation to determine the first moderation | |
// transition that resulted in a published node and takes the timestamp | |
// from that record. | |
$result = db_query(' | |
SELECT m.stamp | |
FROM {node_revision} r | |
LEFT JOIN {node} n ON n.vid = r.vid | |
INNER JOIN {workbench_moderation_node_history} m ON m.vid = r.vid | |
WHERE r.nid = :nid | |
AND m.state = :published_state | |
ORDER BY m.stamp ASC | |
LIMIT 1', array( | |
':nid' => $node->nid, | |
':published_state' => workbench_mod eration_state_published(), | |
))->fetchObject(); | |
if (empty($result->stamp)) { | |
$date = "Unpublished"; | |
} | |
else { | |
$date = format_date($result->stamp, 'long'); | |
} | |
$variables['first_published'] = t('First published on !datetime', array('!datetime' => $date)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment