function openlayers_cck_wkt_element_process in Openlayers 6
Same name and namespace in other branches
- 6.2 modules/openlayers_cck/openlayers_cck.module \openlayers_cck_wkt_element_process()
Process an individual element.
1 string reference to 'openlayers_cck_wkt_element_process'
- openlayers_cck_elements in modules/
openlayers_cck/ openlayers_cck.module - Implementation of FAPI hook_elements().
File
- modules/
openlayers_cck/ openlayers_cck.module, line 363 - This file holds the main Drupal hook functions and private functions for the openlayers_cck module.
Code
function openlayers_cck_wkt_element_process($element, $edit, &$form_state, &$form) {
$field = $form['#field_info'][$element['#parents'][0]];
$delta = $element['#delta'];
$field_name = $field['field_name'];
$widget = $field['widget'];
$field_label = $widget['label'];
$field_key = $element['#columns'][0];
// Make map for input
$rendered_map = _openlayers_cck_render_element_map($field_name, $field_label, $element['#value'], $field);
// Create map element
$element['map'] = array(
'#value' => theme('openlayers_cck_map', $field, $rendered_map),
);
// Create storage element
$element['openlayers_wkt'] = array(
'#type' => 'textarea',
'#rows' => 2,
'#attributes' => array(
'rel' => $rendered_map['id'],
),
// The following values were set by the content module and need
// to be passed down to the nested element.
'#title' => $element['#title'],
'#description' => $element['#description'],
'#required' => $element['#required'],
'#field_name' => $element['#field_name'],
'#type_name' => $element['#type_name'],
'#delta' => $element['#delta'],
'#columns' => $element['#columns'],
);
// Make default value. It will be stored in hidden field
$default_value = '';
if (is_array($element['#value']) && count($element['#value']) > 0) {
// Look for actual values
$values = array();
foreach ($element['#value'] as $id => $data) {
if (is_array($data)) {
// Openlayers WKT
$values[$id] = $data['openlayers_wkt'];
}
elseif (is_string($data)) {
// Geo WKT
$values[$id] = $data;
}
}
// Create string
if (is_array($values) && count($values) > 0) {
$default_value = implode('||', $values);
}
}
// Hidden element. This is used to store a more distinctly
// delimited dataset
$element['openlayers_wkt_hidden'] = array(
'#type' => 'hidden',
'#default_value' => $default_value,
);
// Set #element_validate in a way that it will not wipe out other
// validation functions already set by other modules.
if (empty($element['#element_validate'])) {
$element['#element_validate'] = array();
}
array_unshift($element['#element_validate'], 'openlayers_cck_validate');
// Make sure field info will be available to the validator which
// does not get the values in $form.
$form_state['#field_info'][$field['field_name']] = $field;
return $element;
}