You are here

public function Map::build in Openlayers 7.3

Build render array of a map.

Parameters

array $build: The build array before being completed.

Return value

array The render array.

Overrides MapInterface::build

1 call to Map::build()
Map::render in src/Types/Map.php
Render a build array into HTML.

File

src/Types/Map.php, line 138
Class Map.

Class

Map
Class Map.

Namespace

Drupal\openlayers\Types

Code

public function build(array $build = array()) {
  $map = $this;

  // If this is an asynchronous map flag it as such.
  if ($asynchronous = $this
    ->isAsynchronous()) {
    $map
      ->setOption('async', $asynchronous);
  }
  if (!$map
    ->getOption('target', FALSE)) {
    $this
      ->setOption('target', $this
      ->getId());
  }

  // Transform the options into objects.
  $map
    ->getCollection()
    ->import($map
    ->optionsToObjects());

  // Run prebuild hook to all objects who implements it.
  $map
    ->preBuild($build, $map);
  $capabilities = array();
  if ((bool) $this
    ->getOption('capabilities', FALSE) === TRUE) {
    $items = array_values($this
      ->getOption(array(
      'capabilities',
      'options',
      'table',
    ), array()));
    array_walk($items, 'check_plain');
    $capabilities = array(
      '#weight' => 1,
      '#type' => $this
        ->getOption(array(
        'capabilities',
        'options',
        'container_type',
      ), 'fieldset'),
      '#collapsed' => TRUE,
      '#collapsible' => TRUE,
      '#attached' => array(
        'library' => array(
          array(
            'system',
            'drupal.collapse',
          ),
        ),
      ),
      /*
              '#attributes' => array(
                'class' => array(
                  $this->getOption(array(
                    'capabilities',
                    'options',
                    'collapsible',
                  ), TRUE) ? 'collapsible' : '',
                  $this->getOption(array(
                    'capabilities',
                    'options',
                    'collapsed',
                  ), TRUE) ? 'collapsed' : '',
                ),
              ),
      */
      '#title' => $this
        ->getOption(array(
        'capabilities',
        'options',
        'title',
      ), NULL),
      '#description' => $this
        ->getOption(array(
        'capabilities',
        'options',
        'description',
      ), NULL),
      array(
        '#theme' => 'item_list',
        '#items' => $items,
        '#title' => '',
        '#type' => 'ul',
      ),
    );
  }
  $build = array(
    '#theme' => 'openlayers',
    '#map' => $map,
    '#attached' => $map
      ->getCollection()
      ->getAttached(),
    'map_prefix' => array(),
    'map_suffix' => array(),
    'capabilities' => $capabilities,
  );
  $map
    ->postBuild($build, $map);
  return $build;
}