You are here

function openlayers_map_form_layers_submit in Openlayers 7.3

Map layers config form submit handler.

File

modules/openlayers_ui/src/Plugin/export_ui/OpenlayersMaps.inc, line 345
CTools Export UI plugin definition for maps.

Code

function openlayers_map_form_layers_submit($form, &$form_state) {
  $map = \Drupal\openlayers\Openlayers::load('map', $form_state['item']);
  $layers_enabled = array_filter($form_state['values']['layers'], function ($item) {
    return (bool) $item['enabled'];
  });
  uasort($layers_enabled, function ($a, $b) {
    return $a['weight'] - $b['weight'];
  });
  foreach ($layers_enabled as $data) {

    // Update the layer style.
    if (($layer = \Drupal\openlayers\Openlayers::load('layer', $data['machine_name'])) == TRUE) {
      if (!empty($data['style'])) {
        $layer
          ->setOption('style', $data['style']);
      }
      else {
        $layer
          ->clearOption('style');
      }
      \Drupal\openlayers\Openlayers::save($layer);
    }
  }
  $map
    ->setOption('layers', array_keys($layers_enabled));
  $form_state['item'] = $map
    ->getExport();
}