You are here

function template_preprocess_image_caption_formatter in Image Field Caption 8

Prepares variables for image caption formatter templates.

Default template: image-caption-formatter.html.twig.

Parameters

array $variables: An associative array containing all values from the original function (template_preprocess_image_formatter()) and also:

  • caption: An optional caption text.

File

./image_field_caption.module, line 131
Provides a caption textarea for image fields.

Code

function template_preprocess_image_caption_formatter(&$variables) {
  module_load_include('inc', 'image', 'image.field');

  // Prepare the variables array with the original function.
  template_preprocess_image_formatter($variables);

  // Set the caption value.
  $values = $variables['item']
    ->getValue();
  if (!empty($values['caption'])) {
    $variables['caption'] = $values['caption'];
  }
}