Loading src/Plugin/views/style/LightGallery.php +23 −9 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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); } } } } } Loading templates/lightgallery_views.theme.inc +26 −25 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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(); Loading Loading
src/Plugin/views/style/LightGallery.php +23 −9 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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); } } } } } Loading
templates/lightgallery_views.theme.inc +26 −25 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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(); Loading