You are here

function svg_image_field_formatter_view in Svg Image 7

Implements hook_field_formatter_view().

File

includes/svg_image.field.inc, line 126
Contains hooks and functions related the field settings.

Code

function svg_image_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
  $element = array();

  // 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) {
    if (isset($link_file)) {
      $uri = array(
        'path' => file_create_url($item['uri']),
        'options' => array(),
      );
    }
    $attributes = array();
    $is_svg = svg_image_is_svg($item['uri']);

    // Add custom attributes only for SVG images.
    if ($is_svg) {
      $svg_settings = $display['settings']['svg_settings'];
      foreach ($svg_settings as $attribute => $attribute_value) {
        if (!empty($attribute)) {
          $item[$attribute] = (int) $attribute_value;
        }
      }
    }
    $element[$delta] = array(
      '#theme' => 'image_formatter',
      '#item' => $item,
      '#image_style' => $is_svg === FALSE ? $display['settings']['image_style'] : '',
      '#path' => isset($uri) ? $uri : '',
    );
  }
  return $element;
}