public function MapRenderEventSubscriber::onMapRender in farmOS 2.x
Same name in this branch
- 2.x modules/asset/land/src/EventSubscriber/MapRenderEventSubscriber.php \Drupal\farm_land\EventSubscriber\MapRenderEventSubscriber::onMapRender()
- 2.x modules/asset/structure/src/EventSubscriber/MapRenderEventSubscriber.php \Drupal\farm_structure\EventSubscriber\MapRenderEventSubscriber::onMapRender()
- 2.x modules/core/map/src/EventSubscriber/MapRenderEventSubscriber.php \Drupal\farm_map\EventSubscriber\MapRenderEventSubscriber::onMapRender()
- 2.x modules/core/quantity/src/EventSubscriber/MapRenderEventSubscriber.php \Drupal\quantity\EventSubscriber\MapRenderEventSubscriber::onMapRender()
- 2.x modules/core/ui/map/src/EventSubscriber/MapRenderEventSubscriber.php \Drupal\farm_ui_map\EventSubscriber\MapRenderEventSubscriber::onMapRender()
- 2.x modules/core/map/modules/mapbox/src/EventSubscriber/MapRenderEventSubscriber.php \Drupal\farm_map_mapbox\EventSubscriber\MapRenderEventSubscriber::onMapRender()
React to the MapRenderEvent.
Parameters
\Drupal\farm_map\Event\MapRenderEvent $event: The MapRenderEvent.
File
- modules/
core/ map/ src/ EventSubscriber/ MapRenderEventSubscriber.php, line 48
Class
- MapRenderEventSubscriber
- An event subscriber for the MapRenderEvent.
Namespace
Drupal\farm_map\EventSubscriberCode
public function onMapRender(MapRenderEvent $event) {
// Add the map type cache tags.
$event
->addCacheTags($event
->getMapType()
->getCacheTags());
// Include map behaviors defined by the map type.
$map_behaviors = $event
->getMapType()
->getMapBehaviors();
foreach ($map_behaviors as $behavior) {
$event
->addBehavior($behavior);
}
// Add the WKT behavior if the render element has WKT.
if (!empty($event->element['#map_settings']['wkt'])) {
$event
->addBehavior('wkt');
}
// Add the wkt and geofield behavior to the geofield_widget map.
if (in_array($event
->getMapType()
->id(), [
'geofield_widget',
])) {
$event
->addBehavior('wkt');
$event
->addBehavior('geofield');
}
// Get whether the side panel should be enabled.
$enable_side_panel = $this->configFactory
->get('farm_map.settings')
->get('enable_side_panel');
// Set a cache tag on the map settings to invalidate the cache on changes.
$event
->addCacheTags([
'config:farm_map.settings',
]);
if ($enable_side_panel) {
$event
->addBehavior('enable_side_panel');
}
}