function scheduler_preprocess in Scheduler 2.x
Implements hook_preprocess().
File
- ./
scheduler.module, line 913 - Scheduler publishes and unpublishes entities on dates specified by the user.
Code
function scheduler_preprocess(&$variables, $hook) {
// For entity types that can be processed by Scheduler add the formatted
// publish_on and unpublish_on dates as variables for use in theme templates.
$plugins =& drupal_static(__FUNCTION__);
if (empty($plugins)) {
$plugins = \Drupal::service('scheduler.manager')
->getPluginEntityTypes();
}
// For $hook = 'node' and 'media' the entity is stored in $variables[$hook].
// This is not guaranteed, for example in commerce_product the entity is in
// $variables['product_entity']. This could be extracted if there is a need,
// but for now just skip if the entity is not immediately available.
if (in_array($hook, $plugins) && isset($variables[$hook])) {
$date_formatter = \Drupal::service('date.formatter');
$entity = $variables[$hook];
if (!empty($entity->publish_on->value) && $entity->publish_on->value && is_numeric($entity->publish_on->value)) {
$variables['publish_on'] = $date_formatter
->format($entity->publish_on->value, 'long');
}
if (!empty($entity->unpublish_on->value) && $entity->unpublish_on->value && is_numeric($entity->unpublish_on->value)) {
$variables['unpublish_on'] = $date_formatter
->format($entity->unpublish_on->value, 'long');
}
}
}