You are here

protected function LeafletMap::getAvailableDataSources in Leaflet 2.0.x

Same name and namespace in other branches
  1. 8 modules/leaflet_views/src/Plugin/views/style/LeafletMap.php \Drupal\leaflet_views\Plugin\views\style\LeafletMap::getAvailableDataSources()
  2. 2.1.x modules/leaflet_views/src/Plugin/views/style/LeafletMap.php \Drupal\leaflet_views\Plugin\views\style\LeafletMap::getAvailableDataSources()

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

Return value

array Available data sources.

1 call to LeafletMap::getAvailableDataSources()
LeafletMap::buildOptionsForm in modules/leaflet_views/src/Plugin/views/style/LeafletMap.php
Provide a form to edit options for this plugin.

File

modules/leaflet_views/src/Plugin/views/style/LeafletMap.php, line 323

Class

LeafletMap
Style plugin to render a View output as a Leaflet map.

Namespace

Drupal\leaflet_views\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();
      $definition = $this->fieldTypeManager
        ->getDefinition($type);
      if (is_a($definition['class'], '\\Drupal\\geofield\\Plugin\\Field\\FieldType\\GeofieldItem', TRUE)) {
        $fields_geo_data[$field_id] = $label;
      }
    }
  }
  return $fields_geo_data;
}