Commit 3c790b89 authored by Pucci, Murilo henrique [GTSBR NON-J&J]'s avatar Pucci, Murilo henrique [GTSBR NON-J&J]
Browse files

Issue #3063019 by murilohp, fbreckx: Views display only 1 image

parent 2c40de43
Loading
Loading
Loading
Loading
+23 −9
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@ namespace Drupal\lightgallery\Plugin\views\style;
use Drupal\Core\Entity\EntityFieldManagerInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\file\FileInterface;
use Drupal\file\Plugin\Field\FieldType\FileFieldItemList;
use Drupal\lightgallery\Manager\LightgalleryManager;
use Drupal\views\Plugin\views\style\StylePluginBase;
use Drupal\image\Entity\ImageStyle;
@@ -247,17 +248,30 @@ class LightGallery extends StylePluginBase {
          if (in_array($id, $image_fields)) {
            // This is an image/thumb field.
            // Create URI for selected image style.
            $image_style = $this->view->field[$id]->options['settings']['image_style'];
            $field_settings = $this->view->field[$id]->options['settings'];
            $image_style = NULL;
            if (array_key_exists('lightgallery_core', $field_settings)) {
              $image_style = $field_settings['lightgallery_core']['lightgallery_image_style'];
            }
            if (array_key_exists('image_style', $field_settings)) {
              $image_style = $field_settings['image_style'];
            }

            $field_name = $fields[$id]->field;
            $file = $result[$count]->_entity->{$field_name}->entity;

            $field = $result[$count]->_entity->{$field_name};
            if ($field instanceof FileFieldItemList) {
              foreach ($field as $entity_field) {
                $file = $entity_field->entity;
                if ($file instanceof FileInterface && $uri = $file->getFileUri()) {
                  if (!empty($image_style)) {
                $rendered_fields[$count][$id] = ImageStyle::load($image_style)
                    $rendered_fields[$count][$id][] = ImageStyle::load($image_style)
                      ->buildUrl($uri);
                  }
                  else {
                $rendered_fields[$count][$id] = file_create_url($uri);
                    $rendered_fields[$count][$id][] = file_create_url($uri);
                  }
                }
              }
            }
          }
+26 −25
Original line number Diff line number Diff line
@@ -54,24 +54,24 @@ function template_preprocess_lightgallery_views_style(array &$variables) {
    $rendered_title = FALSE;

    foreach ($row as $field_name => $field) {
      foreach ($field as $image) {
        // Check if field is thumb field.
        if ($field_name == $thumb_field) {
        $rendered_thumb = $field;
          $rendered_thumb = $image;
        }

        // Check if field is image field.
        if ($field_name == $image_field) {
        $rendered_slide = $field;
          $rendered_slide = $image;
        }

        // Check if field is title field.
        if ($field_name == $title_field) {
        $rendered_title = $field;
          $rendered_title = $image;
        }

        // Store field labels.
        $item['field_label'] = $fields[$field_name]->label();
    }

        $item['slide'] = $rendered_slide;
        $item['thumb'] = $rendered_thumb;
@@ -79,9 +79,10 @@ function template_preprocess_lightgallery_views_style(array &$variables) {

        // Set row style to display: hidden or block.
        $item['row_style'] = 'display: block;';

        $items[] = $item;
      }
    }
  }

  // Set unique id, so that multiple instances on one page can be created.
  $unique_id = uniqid();