function openlayers_ui_styles_form_submit in Openlayers 6.2
Submit handler for layers.
File
- modules/
openlayers_ui/ includes/ openlayers_ui.styles.inc, line 393 - This file holds the functions handling styles in the Openlayers UI.
Code
function openlayers_ui_styles_form_submit(&$form, &$form_state) {
$prop_defn = $form_state['values']['style_data']['definitions'];
//$data = $form_state['values']['data'];
$data = $form_state['clicked_button']['#post']['data'];
// Cast and unset values so JS can handle them better,
// Unless value is in form ${attribute}
foreach ($data as $key => $value) {
if (empty($data[$key]['uses_plugin'])) {
$data[$key] = $data[$key]['value'];
if ($data[$key] === '') {
unset($data[$key]);
}
elseif (isset($prop_defn[$key]['type']) && strpos($data[$key], '${') !== 0) {
if ($prop_defn[$key]['type'] == 'integer') {
$data[$key] = (int) $data[$key];
}
elseif ($prop_defn[$key]['type'] == 'float') {
$data[$key] = (double) $data[$key];
}
}
}
else {
$spec = array(
'plugin' => $data[$key]['uses_plugin'],
);
if (isset($data[$key]['plugin']['conf'])) {
$spec['conf'] = $data[$key]['plugin']['conf'];
}
$data[$key] = $spec;
}
}
$form_state['values']['data'] = $data;
$form_state['clicked_button']['#post']['data'] = $data;
$style = new stdClass();
$style->name = $form_state['values']['name'];
$style->title = $form_state['values']['title'];
$style->description = $form_state['values']['description'];
$style->data = $data;
$success = openlayers_style_save($style);
// Redirect to edit page
if ($success) {
drupal_set_message(t('Style saved.'));
$form_state['redirect'] = 'admin/build/openlayers/styles/' . $style->name . '/edit';
}
else {
form_set_error('openlayers', t('Error trying to save style.'));
}
}