You are here

public function GeolocationBlock::build in Geolocation Field 8.3

Same name and namespace in other branches
  1. 8.2 src/Plugin/Block/GeolocationBlock.php \Drupal\geolocation\Plugin\Block\GeolocationBlock::build()

Builds and returns the renderable array for this block plugin.

If a block should not be rendered because it has no content, then this method must also ensure to return no content: it must then only return an empty array, or an empty array with #cache set (with cacheability metadata indicating the circumstances for it being empty).

Return value

array A renderable array representing the content of the block.

Overrides BlockPluginInterface::build

See also

\Drupal\block\BlockViewBuilder

File

src/Plugin/Block/GeolocationBlock.php, line 324

Class

GeolocationBlock
Exposes a map rendered as a block.

Namespace

Drupal\geolocation\Plugin\Block

Code

public function build() {
  $build = [
    '#id' => uniqid("map-"),
    '#type' => 'geolocation_map',
    '#settings' => $this->configuration['map_provider_settings'],
    '#maptype' => $this->configuration['map_provider_id'],
    '#centre' => [],
    '#context' => [
      'block' => $this,
    ],
  ];
  foreach ($this->configuration['locations'] as $index => $location) {
    $build[$index] = [
      '#type' => 'geolocation_map_location',
      '#title' => $location['marker_title'],
      '#coordinates' => $location['marker_coordinates'],
      'content' => [
        '#type' => 'processed_text',
        '#text' => $location['marker_content']['value'],
        '#format' => $location['marker_content']['format'],
      ],
    ];
  }
  $build = $this->mapCenterManager
    ->alterMap($build, $this->configuration['centre'], [
    'block' => $this,
  ]);
  return $build;
}