You are here

function sooperthemes_gridstack_field_formatter_view in Sooperthemes GridStack 7

Implements hook_field_formatter_view().

File

./sooperthemes_gridstack.module, line 134
Code for the SooperThemes GridStack feature.

Code

function sooperthemes_gridstack_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
  $element = array();
  $settings = $display['settings'];
  if ($display['type'] != 'sooperthemes_gridstack_formatter') {
    return $element;
  }

  // Check if the formatter involves a link.
  if ($display['settings']['image_link'] == 'content') {
    $uri = entity_uri($entity_type, $entity);
  }
  elseif ($display['settings']['image_link'] == 'file') {
    $link_file = TRUE;
  }
  foreach ($items as $delta => $item) {
    $image_url = file_create_url($item['uri']);
    if (!empty($settings['image_style'])) {
      $image_url = image_style_url($settings['image_style'], $item['uri']);
    }
    if (isset($link_file)) {
      $uri = array(
        'path' => $image_url,
        'options' => array(),
      );
    }
    $options = array(
      'image_url' => $image_url,
      'path' => isset($uri) ? $uri : '',
    );
    $element[$delta]['#markup'] = theme('sooperthemes_gridstack_formatter', $options);
  }
  return $element;
}