You are here

function theme_picture_formatter in Picture 7.2

Same name and namespace in other branches
  1. 7 picture.module \theme_picture_formatter()

Theme picture formatter.

2 theme calls to theme_picture_formatter()
picture_file_formatter_picture_view in ./picture.file_entity_1.inc
View callback for hook_file_formatter_info().
theme_picture_sizes_formatter in ./picture.module
Theme pictue sizes formatter.

File

./picture.module, line 1166
Picture formatter.

Code

function theme_picture_formatter($variables) {
  if (!isset($variables['breakpoints']) || empty($variables['breakpoints'])) {
    $image_formatter = array(
      '#theme' => 'image_formatter',
      '#item' => $variables['item'],
      '#image_style' => $variables['image_style'],
      '#path' => $variables['path'],
    );
    return drupal_render($image_formatter);
  }
  $item = $variables['item'];
  $responsive_image = array(
    '#theme' => 'picture',
    '#width' => isset($item['width']) ? $item['width'] : NULL,
    '#height' => isset($item['height']) ? $item['height'] : NULL,
    '#style_name' => $variables['image_style'],
    '#breakpoints' => $variables['breakpoints'],
    '#uri' => $item['uri'],
    '#alt' => isset($item['alt']) ? $item['alt'] : '',
    '#attributes' => isset($item['attributes']) ? $item['attributes'] : NULL,
    '#timestamp' => isset($item['timestamp']) ? $item['timestamp'] : NULL,
    '#lazyload' => !empty($variables['lazyload']),
    '#lazyload_aspect_ratio' => !empty($variables['lazyload_aspect_ratio']),
  );
  if (isset($item['title']) && drupal_strlen($item['title']) != 0) {
    $responsive_image['#title'] = $item['title'];
  }
  if (!empty($item['class'])) {
    $class = !empty($responsive_image['#attributes']['class']) ? $responsive_image['#attributes']['class'] : array();
    if (!is_array($class)) {
      $class = array(
        $class,
      );
    }
    $responsive_image['#attributes']['class'] = $class + $item['class'];
  }
  if (is_array($variables['path']) && isset($variables['path']['path'])) {
    $path = $variables['path']['path'];
    $options = isset($variables['path']['options']) ? $variables['path']['options'] : array();
    $options['html'] = TRUE;
    return l(drupal_render($responsive_image), $path, $options);
  }
  return drupal_render($responsive_image);
}