function olebs_blockswitcher_form in Openlayers 7.3
Form for the layer switcher.
2 string references to 'olebs_blockswitcher_form'
- BlockLayerSwitcher::postBuild in modules/
openlayers_library/ src/ Plugin/ Component/ BlockLayerSwitcher/ BlockLayerSwitcher.php - Invoked after an objects render array is built.
- openlayers_block_switcher_block_view in modules/
openlayers_block_switcher/ openlayers_block_switcher.module - Implements hook_block_view().
File
- modules/
openlayers_block_switcher/ openlayers_block_switcher.module, line 93 - Openlayers Block Switcher.
Code
function olebs_blockswitcher_form($form, &$form_state, $map) {
$default_value = array();
$options_overlays = array();
if (!$map instanceof \Drupal\openlayers\Types\MapInterface) {
return FALSE;
}
foreach ($map
->getObjects('layer') as $layer) {
$options_overlays[$layer
->getMachineName()] = $layer
->getName();
if ('1' == $layer
->getOption('visible', 1)) {
$default_value[] = $layer
->getMachineName();
}
}
if (!empty($options_overlays)) {
$form['overlays'] = array(
'#title' => t('Overlays'),
'#type' => 'checkboxes',
'#options' => $options_overlays,
'#default_value' => $default_value,
);
}
// By default we can only rely on the machine name which is a css class.
$form['map'] = array(
'#type' => 'hidden',
'#value' => $map
->getMachineName(),
);
$form['#attached']['css'] = array();
$form['#attached']['library'] = array();
$form['#attached']['js'][] = array(
'data' => drupal_get_path('module', 'openlayers_block_switcher') . '/olbs.js',
'type' => 'file',
);
return $form;
}