1.20.x date.api.php | hook_date_formatter_pre_view_alter(&$entity, &$variables) |
Alter the entity before formatting it.
Parameters
object $entity: The entity object being viewed.
array $variables: The variables passed to the formatter.
- entity: The $entity object.
- entity_type: The $entity_type.
- field: The $field array.
- instance: The $instance array.
- langcode: The $langcode.
- items: The $items array.
- display: The $display array.
- dates: The processed dates array, empty at this point.
- attributes: The attributes array, empty at this point.
File
- modules/
date/ date.api.php, line 40 - Hooks provided by the Date module.
Code
function hook_date_formatter_pre_view_alter(&$entity, &$variables) {
if (!empty($entity->view)) {
$field = $variables['field'];
$date_id = 'date_id_' . $field['field_name'];
$date_delta = 'date_delta_' . $field['field_name'];
$date_item = $entity->view->result[$entity->view->row_index];
if (!empty($date_item->$date_id)) {
$entity->date_id = 'date.' . $date_item->$date_id . '.' . $field['field_name'] . '.' . $date_item->$date_delta . '.0';
}
}
}