You are here

public function PhotoGrid::get_image_field_name in Views Photo Grid 8

Returns the name of the image field used in the view.

File

src/Plugin/views/style/PhotoGrid.php, line 68
Contains \Drupal\views_photo_grid\Plugin\views\style\PhotoGrid.

Class

PhotoGrid
Style plugin to render the photo grid.

Namespace

Drupal\views_photo_grid\Plugin\views\style

Code

public function get_image_field_name() {
  $fields = $this->displayHandler->handlers['field'];

  // Find the first non-excluded image field.
  foreach ($fields as $key => $field) {

    // Get the storage definition in order to determine the field type.
    // Note: This is the same as $field->getFieldStorageDefinition(), but
    // that method is protected and inaccessible here.
    $field_storage_definitions = \Drupal::entityManager()
      ->getFieldStorageDefinitions($field->definition['entity_type']);
    $field_type = $field_storage_definitions[$field->field]
      ->getType();
    if (empty($field->options['exclude']) && $field_type == 'image') {
      return $field->field;
    }
  }
  return FALSE;
}