Allow #behaviors to be added directly to farm_map and farm_map_input elements.
This commit is contained in:
parent
ebeda67be4
commit
4574cc5e9b
|
@ -25,6 +25,7 @@ class FarmMap extends RenderElement {
|
|||
'#theme' => 'farm_map',
|
||||
'#map_type' => 'default',
|
||||
'#map_settings' => [],
|
||||
'#behaviors' => [],
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -38,6 +39,8 @@ class FarmMap extends RenderElement {
|
|||
*
|
||||
* @return array
|
||||
* A renderable array representing the map.
|
||||
*
|
||||
* @see \Drupal\farm_map\Event\MapRenderEvent
|
||||
*/
|
||||
public static function preRenderMap(array $element) {
|
||||
|
||||
|
@ -67,6 +70,15 @@ class FarmMap extends RenderElement {
|
|||
$element['#attached']['library'][] = 'farm_map/farmOS-map';
|
||||
$element['#attached']['library'][] = 'farm_map/farm_map';
|
||||
|
||||
// If #behaviors are included, attach each one.
|
||||
foreach ($element['#behaviors'] as $behavior_name) {
|
||||
/** @var \Drupal\farm_map\Entity\MapBehaviorInterface $behavior */
|
||||
$behavior = \Drupal::entityTypeManager()->getStorage('map_behavior')->load($behavior_name);
|
||||
if (!empty($behavior)) {
|
||||
$element['#attached']['library'][] = $behavior->getLibrary();
|
||||
}
|
||||
}
|
||||
|
||||
// Include the map options.
|
||||
$map_options = $map->getMapOptions();
|
||||
|
||||
|
|
|
@ -36,6 +36,7 @@ class FarmMapInput extends FormElement {
|
|||
'#description_display' => 'before',
|
||||
'#map_type' => 'geofield_widget',
|
||||
'#map_settings' => [],
|
||||
'#behaviors' => [],
|
||||
'#default_value' => '',
|
||||
'#display_raw_geometry' => TRUE,
|
||||
];
|
||||
|
@ -75,6 +76,7 @@ class FarmMapInput extends FormElement {
|
|||
'#type' => 'farm_map',
|
||||
'#map_type' => $element['#map_type'],
|
||||
'#map_settings' => $map_settings,
|
||||
'#behaviors' => $element['#behaviors'],
|
||||
];
|
||||
|
||||
// Add a textarea for the WKT value.
|
||||
|
|
|
@ -72,6 +72,8 @@ class MapRenderEvent extends Event {
|
|||
*
|
||||
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
|
||||
* @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
|
||||
*
|
||||
* @see \Drupal\farm_map\Element\FarmMap
|
||||
*/
|
||||
public function addBehavior(string $behavior_name, array $settings = []) {
|
||||
|
||||
|
|
Loading…
Reference in New Issue