class MapRenderEventSubscriber in farmOS 2.x
Same name in this branch
- 2.x modules/asset/land/src/EventSubscriber/MapRenderEventSubscriber.php \Drupal\farm_land\EventSubscriber\MapRenderEventSubscriber
- 2.x modules/asset/structure/src/EventSubscriber/MapRenderEventSubscriber.php \Drupal\farm_structure\EventSubscriber\MapRenderEventSubscriber
- 2.x modules/core/map/src/EventSubscriber/MapRenderEventSubscriber.php \Drupal\farm_map\EventSubscriber\MapRenderEventSubscriber
- 2.x modules/core/quantity/src/EventSubscriber/MapRenderEventSubscriber.php \Drupal\quantity\EventSubscriber\MapRenderEventSubscriber
- 2.x modules/core/ui/map/src/EventSubscriber/MapRenderEventSubscriber.php \Drupal\farm_ui_map\EventSubscriber\MapRenderEventSubscriber
- 2.x modules/core/map/modules/mapbox/src/EventSubscriber/MapRenderEventSubscriber.php \Drupal\farm_map_mapbox\EventSubscriber\MapRenderEventSubscriber
An event subscriber for the MapRenderEvent.
Adds default behaviors to maps.
Hierarchy
- class \Drupal\farm_map\EventSubscriber\MapRenderEventSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
Expanded class hierarchy of MapRenderEventSubscriber
1 string reference to 'MapRenderEventSubscriber'
- farm_map.services.yml in modules/
core/ map/ farm_map.services.yml - modules/core/map/farm_map.services.yml
1 service uses MapRenderEventSubscriber
File
- modules/
core/ map/ src/ EventSubscriber/ MapRenderEventSubscriber.php, line 14
Namespace
Drupal\farm_map\EventSubscriberView source
class MapRenderEventSubscriber implements EventSubscriberInterface {
/**
* The config factory service.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
private $configFactory;
/**
* Constructor.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The config factory service.
*/
public function __construct(ConfigFactoryInterface $config_factory) {
$this->configFactory = $config_factory;
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
return [
MapRenderEvent::EVENT_NAME => 'onMapRender',
];
}
/**
* React to the MapRenderEvent.
*
* @param \Drupal\farm_map\Event\MapRenderEvent $event
* The MapRenderEvent.
*/
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');
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
MapRenderEventSubscriber:: |
private | property | The config factory service. | |
MapRenderEventSubscriber:: |
public static | function | ||
MapRenderEventSubscriber:: |
public | function | React to the MapRenderEvent. | |
MapRenderEventSubscriber:: |
public | function | Constructor. |