You are here

protected function GeofieldGoogleMapViewStyle::getAvailableEntitySources in Geofield Map 8.2

Get options for the available entity sources.

Entity source controls which entity gets passed to the MapThemer plugin. If not set it will always default to the view base entity.

Return value

array The entity sources list.

1 call to GeofieldGoogleMapViewStyle::getAvailableEntitySources()
GeofieldGoogleMapViewStyle::buildOptionsForm in src/Plugin/views/style/GeofieldGoogleMapViewStyle.php
Provide a form to edit options for this plugin.

File

src/Plugin/views/style/GeofieldGoogleMapViewStyle.php, line 428

Class

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

Namespace

Drupal\geofield_map\Plugin\views\style

Code

protected function getAvailableEntitySources() {
  if ($base_entity_type = $this->view
    ->getBaseEntityType()) {
    $label = $base_entity_type
      ->getLabel();
  }
  else {

    // Fallback to the base table key.
    $base_tables = array_keys($this->view
      ->getBaseTables());

    // A view without a base table should never happen (just in case).
    $label = $base_tables[0] ?? $this
      ->t('Unknown');
  }
  $options = [
    '__base_table' => new TranslatableMarkup('View Base Entity (@entity_type)', [
      '@entity_type' => $label,
    ]),
  ];
  $data = Views::viewsData();

  /** @var \Drupal\views\Plugin\views\HandlerBase $handler */
  foreach ($this->displayHandler
    ->getHandlers('relationship') as $relationship_id => $handler) {
    if (($table = $data
      ->get($handler->definition['base'])) && !empty($table['table']['entity type'])) {
      try {
        $entity_type = $this->entityManager
          ->getDefinition($table['table']['entity type']);
      } catch (\Exception $e) {
        $entity_type = NULL;
      }
      $options[$relationship_id] = new TranslatableMarkup('@relationship (@entity_type)', [
        '@relationship' => $handler
          ->adminLabel(),
        '@entity_type' => $entity_type
          ->getLabel(),
      ]);
    }
  }
  return $options;
}