You are here

public function ControlCustomRecenter::alterMap in Geolocation Field 8.3

Same name and namespace in other branches
  1. 8.2 modules/geolocation_google_maps/src/Plugin/geolocation/MapFeature/ControlCustomRecenter.php \Drupal\geolocation_google_maps\Plugin\geolocation\MapFeature\ControlCustomRecenter::alterMap()

Alter render array.

Parameters

array $render_array: Render array.

array $feature_settings: The current feature settings.

array $context: Context like field formatter, field widget or view.

Return value

array Render array.

Overrides ControlCustomElementBase::alterMap

File

modules/geolocation_google_maps/src/Plugin/geolocation/MapFeature/ControlCustomRecenter.php, line 22

Class

ControlCustomRecenter
Provides Recenter control element.

Namespace

Drupal\geolocation_google_maps\Plugin\geolocation\MapFeature

Code

public function alterMap(array $render_array, array $settings, array $context = []) {
  $render_array = parent::alterMap($render_array, $settings, $context);
  $render_array['#attached'] = BubbleableMetadata::mergeAttachments(empty($render_array['#attached']) ? [] : $render_array['#attached'], [
    'library' => [
      'geolocation_google_maps/mapfeature.' . $this
        ->getPluginId(),
    ],
    'drupalSettings' => [
      'geolocation' => [
        'maps' => [
          $render_array['#id'] => [
            $this
              ->getPluginId() => [
              'enable' => TRUE,
            ],
          ],
        ],
      ],
    ],
  ]);
  $render_array['#controls'][$this->pluginId]['control_recenter'] = [
    '#type' => 'html_tag',
    '#tag' => 'button',
    '#value' => $this
      ->t('Recenter'),
    '#attributes' => [
      'class' => [
        'recenter',
      ],
    ],
  ];
  return $render_array;
}