You are here

function scheduler_preprocess_node in Scheduler 8

Same name and namespace in other branches
  1. 6 scheduler.module \scheduler_preprocess_node()
  2. 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

template_preprocess_node()

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');
  }
}