You are here

fotorama_gallery.module in Fotorama Gallery 8

Same filename and directory in other branches
  1. 8.2 fotorama_gallery.module

Add new formatter display to image field.

File

fotorama_gallery.module
View source
<?php

/**
 * @file
 * Add new formatter display to image field.
 */

/**
 * Implements hook_theme().
 */
function fotorama_gallery_theme() {
  return [
    'fotorama_gallery_field' => [
      'render element' => 'element',
    ],
  ];
}

/**
 * Implements template_preprocess_fotorama_gallery_field().
 */
function template_preprocess_fotorama_gallery_field(&$variables, $hook) {
  $element = $variables['element'];
  $variables['label_hidden'] = $element['#label_display'] == 'hidden';

  // Always set the field label - allow themes to decide whether to display it.
  // In addition the label should be rendered but hidden to support screen
  // readers.
  $variables['label'] = $element['#title'];
  $variables['multiple'] = $element['#is_multiple'];
  $variables['items'] = [];
  $delta = 0;
  while (!empty($element[$delta])) {
    $variables['items'][$delta]['content'] = $element[$delta];
    $delta++;
  }
  $variables['attributes'] = $variables['element']['attributes'];
}