You are here

public function LightGallery::renderFields in Lightgallery 8

Render fields.

@Override parent.

Overrides StylePluginBase::renderFields

File

src/Plugin/views/style/LightGallery.php, line 234

Class

LightGallery
Style plugin to render each item in an ordered or unordered list.

Namespace

Drupal\lightgallery\Plugin\views\style

Code

public function renderFields(array $result) {
  $rendered_fields = [];
  $this->view->row_index = 0;
  $keys = array_keys($this->view->field);

  // If all fields have a field::access FALSE there might be no fields, so
  // there is no reason to execute this code.
  if (!empty($keys)) {
    $fields = $this->view->field;
    $field_sources = $this
      ->confGetFieldSources();
    $image_fields = array_keys($field_sources['field_options_images']);
    foreach ($result as $count => $row) {
      $this->view->row_index = $count;
      foreach ($keys as $id) {
        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_name = $fields[$id]->field;
          $file = $result[$count]->_entity->{$field_name}->entity;
          if ($file instanceof FileInterface && ($uri = $file
            ->getFileUri())) {
            if (!empty($image_style)) {
              $rendered_fields[$count][$id] = ImageStyle::load($image_style)
                ->buildUrl($uri);
            }
            else {
              $rendered_fields[$count][$id] = file_create_url($uri);
            }
          }
        }
        else {

          // Just render the field as views would do.
          $rendered_fields[$count][$id] = $this->view->field[$id]
            ->render($row);
        }
      }

      // Populate row tokens.
      $this->rowTokens[$count] = $this->view->field[$id]
        ->getRenderTokens([]);
    }
  }
  unset($this->view->row_index);
  return $rendered_fields;
}