public function LegacyFormatter::prepareView

Implements Drupal\field\Plugin\Type\Formatter\FormatterInterface::prepareView().

Overrides FormatterBase::prepareView

File

drupal/core/modules/field/lib/Drupal/field/Plugin/field/formatter/LegacyFormatter.php, line 77
Definition of Drupal\field\Plugin\field\formatter\LegacyFormatter.

Class

LegacyFormatter
Plugin implementation for legacy formatters.

Namespace

Drupal\field\Plugin\field\formatter

Code

public function prepareView(array $entities, $langcode, array &$items) {
  $definition = $this
    ->getDefinition();
  $function = $definition['module'] . '_field_formatter_prepare_view';
  if (function_exists($function)) {

    // Grab the entity type from the first entity.
    $entity = current($entities);
    $entity_type = $entity
      ->entityType();

    // hook_field_formatter_prepare_view() received an array of display properties,
    // for each entity (the same hook could end up being called for different formatters,
    // since one hook implementation could provide several formatters).
    $display = array(
      'type' => $this
        ->getPluginId(),
      'settings' => $this
        ->getSettings(),
      'weight' => $this->weight,
      'label' => $this->label,
    );
    $displays = array();
    foreach ($entities as $entity) {
      $displays[$entity
        ->id()] = $display;
    }
    $function($entity_type, $entities, $this->field, $this->instance, $langcode, $items, $displays);
  }
}