You are here

public function Baidu::alterRenderArray in Geolocation Field 8.3

Alter render array.

Parameters

array $render_array: Render array.

array $map_settings: The current map settings.

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

Return value

array Render attachments.

Overrides MapProviderBase::alterRenderArray

File

modules/geolocation_baidu/src/Plugin/geolocation/MapProvider/Baidu.php, line 118

Class

Baidu
Provides Baidu Maps API.

Namespace

Drupal\geolocation_baidu\Plugin\geolocation\MapProvider

Code

public function alterRenderArray(array $render_array, array $map_settings, array $context = []) {
  $config = \Drupal::config('baidu_maps.settings');
  $render_array['#attached'] = BubbleableMetadata::mergeAttachments(empty($render_array['#attached']) ? [] : $render_array['#attached'], [
    'library' => [
      'geolocation_baidu/baidu_maps',
      'geolocation_baidu/geolocation.baidu',
    ],
    'drupalSettings' => [
      'geolocation' => [
        'baiduKey' => $config
          ->get('key'),
        'maps' => [
          $render_array['#id'] => [
            'settings' => [
              'baidu_settings' => $map_settings,
            ],
          ],
        ],
      ],
    ],
  ]);
  return parent::alterRenderArray($render_array, $map_settings, $context);
}