protected function LeafletMap::getAvailableEntitySources in Leaflet 2.0.x
Same name and namespace in other branches
- 8 modules/leaflet_views/src/Plugin/views/style/LeafletMap.php \Drupal\leaflet_views\Plugin\views\style\LeafletMap::getAvailableEntitySources()
- 2.1.x modules/leaflet_views/src/Plugin/views/style/LeafletMap.php \Drupal\leaflet_views\Plugin\views\style\LeafletMap::getAvailableEntitySources()
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 LeafletMap::getAvailableEntitySources()
- 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 361
Class
- LeafletMap
- Style plugin to render a View output as a Leaflet map.
Namespace
Drupal\leaflet_views\Plugin\views\styleCode
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;
}