degov-8.x-2.0/modules/degov_paragraph_map/degov_paragraph_map.module
modules/degov_paragraph_map/degov_paragraph_map.module
<?php
use Drupal\Core\Form\FormStateInterface;
use Drupal\degov_common\Common;
/**
* Implements hook_preprocess().
*/
function degov_paragraph_map_preprocess(&$variables, $hook, &$info) {
// Add template suggestions and libraries implemented in this module.
Common::addThemeSuggestions($variables, $hook, $info, [
'module_name' => 'degov_paragraph_map',
'entity_type' => 'paragraph',
'entity_bundles' => ['map'],
'entity_view_modes' => ['default', 'preview'],
]);
}
/**
* Implements hook_field_widget_form_alter().
*/
function degov_paragraph_map_field_widget_form_alter(&$element, FormStateInterface $form_state, $context) {
/** @var \Drupal\Core\Field\WidgetBase $widget */
$widget = $context['widget'];
// Limit the view mode selection field to the selected view modes.
if ($widget->getPluginId() == 'entity_reference_paragraphs' && !empty($element['subform']['field_map_address_view_mode'])) {
$allowed_view_modes = [
'osm_map' => t('OSM Map'),
'default_map' => t('Google Map'),
];
$element['subform']['field_map_address_view_mode']['widget']['#options'] = $allowed_view_modes;
}
}
