MapRenderEventSubscriber.php in farmOS 2.x
Same filename in this branch
- 2.x modules/asset/land/src/EventSubscriber/MapRenderEventSubscriber.php
- 2.x modules/asset/structure/src/EventSubscriber/MapRenderEventSubscriber.php
- 2.x modules/core/map/src/EventSubscriber/MapRenderEventSubscriber.php
- 2.x modules/core/quantity/src/EventSubscriber/MapRenderEventSubscriber.php
- 2.x modules/core/ui/map/src/EventSubscriber/MapRenderEventSubscriber.php
- 2.x modules/core/map/modules/mapbox/src/EventSubscriber/MapRenderEventSubscriber.php
Namespace
Drupal\quantity\EventSubscriberFile
modules/core/quantity/src/EventSubscriber/MapRenderEventSubscriber.phpView source
<?php
namespace Drupal\quantity\EventSubscriber;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\farm_map\Event\MapRenderEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
* An event subscriber for the MapRenderEvent.
*
* Adds the quantity.system_of_measurement setting to maps.
*/
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.
*
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
* @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
*/
public function onMapRender(MapRenderEvent $event) {
// Set a cache tag on the quantity settings in case this ever changes.
$event
->addCacheTags([
'config:quantity.settings',
]);
// Add the system of measurement to drupalSettings.farm_map.units.
$measurement = $this->configFactory
->get('quantity.settings')
->get('system_of_measurement');
$event->element['#attached']['drupalSettings']['farm_map']['units'] = $measurement;
}
}
Classes
Name | Description |
---|---|
MapRenderEventSubscriber | An event subscriber for the MapRenderEvent. |