You are here

protected function FormatterTrait::updateElements in Image Hover Effects 8

2 calls to FormatterTrait::updateElements()
ImageFormatter::viewElements in src/Plugin/Field/FieldFormatter/ImageFormatter.php
Builds a renderable array for a field value.
ResponsiveImageFormatter::viewElements in src/Plugin/Field/FieldFormatter/ResponsiveImageFormatter.php
Builds a renderable array for a field value.

File

src/Plugin/Field/FieldFormatter/FormatterTrait.php, line 62

Class

FormatterTrait
Helper methods for image formatters.

Namespace

Drupal\image_hover_effects\Plugin\Field\FieldFormatter

Code

protected function updateElements(array &$elements, EntityInterface $entity, $theme) {
  $token = \Drupal::token();
  $settings = $this
    ->getSettings();
  $entity_type = $entity
    ->getEntityTypeId();
  foreach ($elements as $delta => $element) {
    $elements[$delta]['#theme'] = $theme;
    $elements[$delta]['#link_attributes'] = [
      'class' => [
        'ihe-overlay',
        Html::getClass('ihe-overlay--' . $settings['hover_effect']),
      ],
      'data-hover' => $token
        ->replace($settings['hover_text'], [
        $entity_type => $entity,
      ]),
    ];
  }
  $elements['#attached']['library'][] = 'image_hover_effects/image_hover_effects';
  return $elements;
}