You are here

function template_preprocess_flexslider_picture_list in Picture 7

Same name and namespace in other branches
  1. 7.2 flexslider_picture/theme/flexslider_picture.theme.inc \template_preprocess_flexslider_picture_list()

Process the items and prepare the item slides to be rendered.

Parameters

$vars:

1 string reference to 'template_preprocess_flexslider_picture_list'
flexslider_picture_theme_registry_alter in flexslider_picture/flexslider_picture.module
Implements hook_theme_registry_alter().

File

flexslider_picture/theme/flexslider_picture.theme.inc, line 14
Picture formatter with flexslider support.

Code

function template_preprocess_flexslider_picture_list(&$vars) {
  $optionset =& $vars['settings']['optionset'];

  // Check if this is a picture optionset.
  $vars['picture_formatter_enabled'] = isset($optionset->imagestyle_type) && !empty($optionset->imagestyle_type) && $optionset->imagestyle_type == 'picture_mapping';
  if ($vars['picture_formatter_enabled']) {
    $items =& $vars['items'];

    // Get the breakpoints based on the mapping.
    $fallback_image_style = '';
    $mappings = picture_mapping_load($optionset->mapping);
    $breakpoint_styles = picture_get_mapping_breakpoints($mappings, $fallback_image_style);

    // If colorbox is enabled build additional configuration.
    if (!empty($optionset->options['colorboxEnabled'])) {

      // Add additional necessary scripts and styles.
      drupal_add_js(drupal_get_path('module', 'picture') . '/picture_colorbox.js');
      drupal_add_css(drupal_get_path('module', 'picture') . '/picture_colorbox.css');
      if (!variable_get('colorbox_inline', 0)) {
        drupal_add_js(drupal_get_path('module', 'colorbox') . '/js/colorbox_inline.js');
      }
      $colorbox_fallback_image_style = '';
      $mappings = picture_mapping_load($optionset->options['colorboxImageStyle']);
      $colorbox_breakpoints = picture_get_mapping_breakpoints($mappings, $colorbox_fallback_image_style);

      // Grouping ID for the colorbox gallery. Use more_entropy to ensure the
      // php function works on every environment (cygwin).
      $colorbox_group_id = uniqid('flexgroup', TRUE);
    }

    // Prepare the item slides to be passed to render().
    foreach ($items as $i => &$item) {
      if (isset($item['item'])) {
        $item['slide'] = array(
          '#theme' => 'picture',
          '#style_name' => $optionset->imagestyle_normal,
          '#uri' => $item['item']['uri'],
          '#alt' => $item['item']['alt'],
          '#title' => $item['item']['title'],
          '#breakpoints' => $breakpoint_styles,
        );

        // If colorbox is enabled change the theming function and add settings.
        if (!empty($optionset->options['colorboxEnabled'])) {
          $item['slide'] = array(
            '#theme' => 'picture_formatter_colorbox',
            '#item' => $item['item'],
            '#image_style' => $optionset->imagestyle_normal,
            '#path' => $item['item']['uri'],
            '#colorbox_image_style' => $colorbox_fallback_image_style,
            '#colorbox' => $colorbox_breakpoints,
            '#colorbox_group_id' => $colorbox_group_id,
            '#alt' => $item['item']['alt'],
            '#title' => $item['item']['title'],
            '#breakpoints' => $breakpoint_styles,
          );
        }
        if (!isset($item['thumb'])) {
          $item['thumb'] = image_style_url($optionset->imagestyle_thumbnail, $item['item']['uri']);
        }
      }
    }
  }
}