You are here

function bootstrap_gallery_preprocess_views_view_field in Bootstrap - Photo Gallery 7.3

Prepare Gallery image field wrapper @TODO: add video field support

File

./bootstrap_gallery.module, line 77

Code

function bootstrap_gallery_preprocess_views_view_field(&$vars) {
  if ($vars['view']->plugin_name == 'bootstrap_gallery') {
    $view = $vars['view'];
    $field = $vars['field'];
    $field_name = $field->field;
    $options = bootstrap_gallery_get_options($view->style_plugin->options);
    $plugin_image_field = $options['image_field'];
    $plugin_image_title = $options['image_title'];
    if ($field_name == $plugin_image_field) {
      $row = (array) $vars['row'];
      if (isset($row["field_{$field_name}"]) && ($image = $row["field_{$field_name}"])) {
        if (!isset($options['image_style']) || $options['image_style'] == 'original') {
          $original_image = file_create_url($image[0]['raw']['uri']);
        }
        else {
          $original_image = image_style_url($options['image_style'], $image[0]['raw']['uri']);
        }
        $thumbnail = $vars['field']
          ->advanced_render($vars['row']);
        if (isset($image[0]['raw']['title'])) {
          $title = $image[0]['raw']['title'];
        }
        if ($plugin_image_title != 'default') {
          if (isset($view->field[$plugin_image_title]) && ($title_field = $view->field[$plugin_image_title])) {
            $field_object = $title_field
              ->get_value($vars['row']);
            if (is_string($field_object)) {
              $title = $field_object;
            }
            else {
              if (is_array($field_object) && isset($field_object[0]['value'])) {
                $title = $field_object[0]['value'];
              }
              else {
                drupal_set_message(t('Bootstrap Gallery: Selected image title field type is not supported'), 'warning');
              }
            }
          }
        }
        $vars['output'] = theme('bootstrap_gallery_item', array(
          'original_image' => $original_image,
          'thumbnail' => $thumbnail,
          'title' => $title,
        ));
      }
    }
  }
}