You are here

function hook_date_formatter_pre_view_alter in Date 8

Same name and namespace in other branches
  1. 7.3 date.api.php \hook_date_formatter_pre_view_alter()
  2. 7.2 date.api.php \hook_date_formatter_pre_view_alter()

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.
  • rdf_mapping: The RDF mapping array.
  • add_rdf: If module_exists('rdf').
1 function implements hook_date_formatter_pre_view_alter()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

date_views_date_formatter_pre_view_alter in date_views/date_views.module
Implements hook_date_formatter_view_alter().
6 invocations of hook_date_formatter_pre_view_alter()
DateDefaultFormatter::viewElements in lib/Drupal/date/Plugin/field/formatter/DateDefaultFormatter.php
Implements Drupal\field\Plugin\Type\Formatter\FormatterInterface::viewElements().
DateFieldDefaultFormatter::viewElements in date_field/lib/Drupal/date_field/Plugin/field/formatter/DateFieldDefaultFormatter.php
Implements Drupal\field\Plugin\Type\Formatter\FormatterInterface::viewElements().
DateFieldFormatIntervalFormatter::viewElements in date_field/lib/Drupal/date_field/Plugin/field/formatter/DateFieldFormatIntervalFormatter.php
Implements Drupal\field\Plugin\Type\Formatter\FormatterInterface::viewElements().
DateFieldPlainFormatter::viewElements in date_field/lib/Drupal/date_field/Plugin/field/formatter/DateFieldPlainFormatter.php
Implements Drupal\field\Plugin\Type\Formatter\FormatterInterface::viewElements().
DatePlainFormatter::viewElements in lib/Drupal/date/Plugin/field/formatter/DatePlainFormatter.php
Implements Drupal\field\Plugin\Type\Formatter\FormatterInterface::viewElements().

... See full list

File

./date.api.php, line 46
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';
    }
  }
}