function scheduler_preprocess_node in Scheduler 8
Same name and namespace in other branches
- 6 scheduler.module \scheduler_preprocess_node()
- 7 scheduler.module \scheduler_preprocess_node()
Prepares variables for node templates.
Makes the publish_on and unpublish_on data available as theme variables.
See also
File
- ./
scheduler.module, line 637 - Scheduler publishes and unpublishes nodes on dates specified by the user.
Code
function scheduler_preprocess_node(&$variables) {
$date_formatter = \Drupal::service('date.formatter');
/** @var \Drupal\node\NodeInterface $node */
$node = $variables['node'];
if (!empty($node->publish_on->value) && $node->publish_on->value && is_numeric($node->publish_on->value)) {
$variables['publish_on'] = $date_formatter
->format($node->publish_on->value, 'long');
}
if (!empty($node->unpublish_on->value) && $node->unpublish_on->value && is_numeric($node->unpublish_on->value)) {
$variables['unpublish_on'] = $date_formatter
->format($node->unpublish_on->value, 'long');
}
}