You are here

protected function OpenlayersMap::getAvailableDataSources in Openlayers 8.4

Get a list of fields and a sublist of geo data fields in this view.

Return value

array Available data sources.

1 call to OpenlayersMap::getAvailableDataSources()
OpenlayersMap::buildOptionsForm in src/Plugin/views/style/OpenlayersMap.php
Overrides \Drupal\views\Plugin\views\style\StylePluginBase\StylePluginBase::buildOptionsForm().

File

src/Plugin/views/style/OpenlayersMap.php, line 160
Definition of Drupal\openlayers\Plugin\views\style\OpenlayersMap.

Class

OpenlayersMap
Style plugin to render geodata on an Openlayers map.

Namespace

Drupal\openlayers\Plugin\views\style

Code

protected function getAvailableDataSources() {
  $fields_geo_data = [];

  /* @var \Drupal\views\Plugin\views\ViewsHandlerInterface $handler) */
  foreach ($this->displayHandler
    ->getHandlers('field') as $field_id => $handler) {
    $label = $handler
      ->adminLabel() ?: $field_id;
    $this->viewFields[$field_id] = $label;
    if (is_a($handler, '\\Drupal\\views\\Plugin\\views\\field\\EntityField')) {

      /* @var \Drupal\views\Plugin\views\field\EntityField $handler */
      try {
        $entity_type = $handler
          ->getEntityType();
      } catch (\Exception $e) {
        $entity_type = NULL;
      }
      $field_storage_definitions = $this->entityFieldManager
        ->getFieldStorageDefinitions($entity_type);
      $field_storage_definition = $field_storage_definitions[$handler->definition['field_name']];
      $type = $field_storage_definition
        ->getType();
      if (in_array($type, [
        'geofield',
        'geolocation',
      ])) {
        $fields_geo_data[$field_id] = $label;
      }
    }
  }
  return $fields_geo_data;
}