You are here

public function MapSwitcher::postBuild in Openlayers 7.3

Invoked after an objects render array is built.

Mostly invoked by the map object.

Parameters

array $build: The array with the build information.

\Drupal\openlayers\Types\ObjectInterface $context: The context of the build. Mostly the map object.

Overrides Base::postBuild

File

modules/openlayers_library/src/Plugin/Component/MapSwitcher/MapSwitcher.php, line 24
Component: MapSwitcher.

Class

MapSwitcher
Class MapSwitcher.

Namespace

Drupal\openlayers_library\Plugin\Component\MapSwitcher

Code

public function postBuild(array &$build, ObjectInterface $context = NULL) {
  parent::postBuild($build, $context);
  $options = array();
  foreach (\Drupal\openlayers\Openlayers::loadAllExportable('Map') as $machine_name => $data) {
    if (!is_object($data) || property_exists($data, 'disabled') && ($data->disabled == 1 || $data->disabled == TRUE)) {
      continue;
    }
    $options[$machine_name] = $data->name;
  }
  $wrapper = 'wrapper-' . $context
    ->getId();
  $build['openlayers_default_map'] = array(
    '#type' => 'select',
    '#title' => 'Chose a map',
    '#multiple' => FALSE,
    '#options' => $options,
    '#ajax' => array(
      'callback' => '_openlayers_ajax_reload_default_map',
      'method' => 'replace',
      'wrapper' => $wrapper,
      'effect' => 'fade',
    ),
  );
  $build['form'] = array(
    '#type' => 'container',
    '#attributes' => array(
      'id' => $wrapper,
    ),
  );
  $build['form'][$context
    ->getId()]['map'] = $build['map'];
  unset($build['map']);
}