You are here

function template_preprocess_linkimage_formatter in Link Image Field 8

Prepares variables for linkimagefield formatter template.

Parameters

$variables: An associative array containing:

  • element: An array of elements to display in formatter.
  • image_style: An optional image style.
  • item_attributes: An array of image attributes.

File

./linkimagefield.module, line 31
Defines theming for a link image field.

Code

function template_preprocess_linkimage_formatter(&$variables) {
  $element = $variables['element'];
  if ($element['#image_style']) {
    $image = array(
      '#theme' => 'image_style',
      '#style_name' => $element['#image_style'],
    );
  }
  else {
    $image = array(
      '#theme' => 'image',
    );
  }
  $image['#attributes'] = $element['#item_attributes'];
  $item = $element['#item'];

  // Do not output an empty 'title' attribute.
  if (drupal_strlen($item->title) != 0) {
    $image['#title'] = $item->title;
  }
  if (($entity = $item->entity) && empty($item->uri)) {
    $image['#uri'] = $entity
      ->getFileUri();
  }
  else {
    $image['#uri'] = $item->uri;
  }
  foreach (array(
    'width',
    'height',
    'alt',
  ) as $key) {
    $image["#{$key}"] = $item->{$key};
  }
  $variables['image'] = drupal_render($image);
  $variables['attributes'] = array(
    'title' => $item->title,
    'target' => $item->target,
    'rel' => $item->rel,
    'class' => $item->class,
  );
  $variables['url'] = $item->url;
}