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.
Hierarchy
- class \Drupal\farm_land\EventSubscriber\MapRenderEventSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface uses StringTranslationTrait
Expanded class hierarchy of MapRenderEventSubscriber
1 string reference to 'MapRenderEventSubscriber'
- farm_land.services.yml in modules/
asset/ land/ farm_land.services.yml - modules/asset/land/farm_land.services.yml
1 service uses MapRenderEventSubscriber
File
- modules/
asset/ land/ src/ EventSubscriber/ MapRenderEventSubscriber.php, line 15
Namespace
Drupal\farm_land\EventSubscriberView source
class MapRenderEventSubscriber implements EventSubscriberInterface {
use StringTranslationTrait;
/**
* Land asset type.
*
* @var \Drupal\asset\Entity\AssetTypeInterface
*/
protected $landAssetType;
/**
* The layer style loader service.
*
* @var \Drupal\farm_map\layerStyleLoader
*/
protected $layerStyleLoader;
/**
* MapRenderEventSubscriber Constructor.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager service.
* @param \Drupal\farm_map\layerStyleLoaderInterface $layer_style_loader
* The layer style loader service.
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager, layerStyleLoaderInterface $layer_style_loader) {
$this->landAssetType = $entity_type_manager
->getStorage('asset_type')
->load('land');
$this->layerStyleLoader = $layer_style_loader;
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
return [
MapRenderEvent::EVENT_NAME => [
'onMapRender',
-100,
],
];
}
/**
* React to the MapRenderEvent.
*
* @param \Drupal\farm_map\Event\MapRenderEvent $event
* The MapRenderEvent.
*/
public function onMapRender(MapRenderEvent $event) {
// Get the map ID.
$map_id = $event
->getmapType()
->id();
// Add land type layers to dashboard map.
if ($map_id == 'dashboard') {
$layers = [];
// Define the parent group.
$group = $this
->t('Locations');
// Create a layer group for the asset type.
$layers['land'] = [
'group' => $group,
'label' => $this->landAssetType
->label(),
'is_group' => TRUE,
];
// Load land types.
$land_types = FarmLandType::loadMultiple();
// Create a layer for each sub-type.
foreach ($land_types as $land_type) {
/** @var \Drupal\farm_map\Entity\LayerStyleInterface $layer_style */
$conditions = [
'asset_type' => 'land',
'land_type' => $land_type
->id(),
];
$layer_style = $this->layerStyleLoader
->load($conditions);
if (!empty($layer_style)) {
$color = $layer_style
->get('color');
}
$layers['land_' . $land_type
->id()] = [
'group' => $this->landAssetType
->label(),
'label' => $land_type
->label(),
'asset_type' => 'land',
'filters' => [
'land_type_value[]' => $land_type
->id(),
],
'color' => $color ?? 'orange',
'zoom' => TRUE,
];
}
// Add layers to the map settings.
$settings[$event
->getMapTargetId()]['asset_type_layers'] = $layers;
$event
->addSettings($settings);
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
MapRenderEventSubscriber:: |
protected | property | Land asset type. | |
MapRenderEventSubscriber:: |
protected | property | The layer style loader service. | |
MapRenderEventSubscriber:: |
public static | function | ||
MapRenderEventSubscriber:: |
public | function | React to the MapRenderEvent. | |
MapRenderEventSubscriber:: |
public | function | MapRenderEventSubscriber Constructor. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 4 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |