You are here

function dxpr_gridstack_field_formatter_view in DXPR GridStack 7

Implements hook_field_formatter_view().

File

./dxpr_gridstack.module, line 134
Code for the DXPR GridStack feature.

Code

function dxpr_gridstack_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
  $element = array();
  $settings = $display['settings'];
  if ($display['type'] != 'dxpr_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('dxpr_gridstack_formatter', $options);
  }
  return $element;
}