You are here

protected function LeafletSettingsElementsTrait::generateMapGeneralSettings in Leaflet 2.1.x

Same name and namespace in other branches
  1. 8 src/LeafletSettingsElementsTrait.php \Drupal\leaflet\LeafletSettingsElementsTrait::generateMapGeneralSettings()
  2. 2.0.x src/LeafletSettingsElementsTrait.php \Drupal\leaflet\LeafletSettingsElementsTrait::generateMapGeneralSettings()

Generate the Leaflet Map General Settings.

Parameters

array $elements: The form elements.

array $settings: The settings.

2 calls to LeafletSettingsElementsTrait::generateMapGeneralSettings()
LeafletDefaultFormatter::settingsForm in src/Plugin/Field/FieldFormatter/LeafletDefaultFormatter.php
Returns a form to configure settings for the formatter.
LeafletMap::buildOptionsForm in modules/leaflet_views/src/Plugin/views/style/LeafletMap.php
Provide a form to edit options for this plugin.

File

src/LeafletSettingsElementsTrait.php, line 120

Class

LeafletSettingsElementsTrait
Class LeafletSettingsElementsTrait.

Namespace

Drupal\leaflet

Code

protected function generateMapGeneralSettings(array &$elements, array $settings) {
  $leaflet_map_options = [];
  foreach (leaflet_map_get_info() as $key => $map) {
    $leaflet_map_options[$key] = $map['label'];
  }
  $leaflet_map = isset($settings['leaflet_map']) ? $settings['leaflet_map'] : $settings['map'];
  $elements['leaflet_map'] = [
    '#title' => $this
      ->t('Leaflet Map'),
    '#type' => 'select',
    '#options' => $leaflet_map_options,
    '#default_value' => $leaflet_map,
    '#required' => TRUE,
  ];
  $elements['height'] = [
    '#title' => $this
      ->t('Map Height'),
    '#type' => 'number',
    '#default_value' => $settings['height'],
    '#description' => $this
      ->t('Note: This can be left empty to make the Map fill its parent container height.'),
  ];
  $elements['height_unit'] = [
    '#title' => t('Map height unit'),
    '#type' => 'select',
    '#options' => [
      'px' => t('px'),
      '%' => t('%'),
      'vh' => t('vh'),
    ],
    '#default_value' => $settings['height_unit'],
    '#description' => t("Whether height is absolute (pixels) or relative (percent, vertical height).<br><strong>Note:</strong> In case of Percent the Leaflet Map should be wrapped in a container element with defined Height, otherwise won't show up."),
  ];
  $elements['hide_empty_map'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Hide Map if empty'),
    '#description' => $this
      ->t('Check this option not to render the Map at all, if empty (no output results).'),
    '#default_value' => $settings['hide_empty_map'],
    '#return_value' => 1,
    '#states' => [
      'invisible' => [
        ':input[name="fields[field_geofield][settings_edit_form][settings][multiple_map]"]' => [
          'checked' => TRUE,
        ],
      ],
    ],
  ];
  $elements['disable_wheel'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Disable zoom using mouse wheel'),
    '#description' => $this
      ->t("If enabled, the mouse wheel won't change the zoom level of the map."),
    '#default_value' => $settings['disable_wheel'],
    '#return_value' => 1,
  ];
  $elements['fullscreen_control'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Fullscreen Control'),
    '#description' => $this
      ->t('Enable the Fullscreen View of the Map.'),
    '#default_value' => $settings['fullscreen_control'],
    '#return_value' => 1,
  ];
  $elements['gesture_handling'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Gesture Handling'),
    '#description' => $this
      ->t('Enable the @gesture_handling_link functionality for the Map.', [
      '@gesture_handling_link' => $this->link
        ->generate($this
        ->t('Leaflet Gesture Handling Library'), Url::fromUri('https://github.com/elmarquis/Leaflet.GestureHandling', [
        'absolute' => TRUE,
        'attributes' => [
          'target' => 'blank',
        ],
      ])),
    ]),
    '#default_value' => $settings['gesture_handling'],
    '#return_value' => 1,
  ];
}