You are here

function openlayers_cck_wkt_element_process in Openlayers 6.2

Same name and namespace in other branches
  1. 6 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 340
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'];
  $field_key = $element['#columns'][0];

  // Make map for input
  $rendered_map = _openlayers_cck_render_element_map($field_name, $field['widget']['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'],
    // TODO: more standard way of saying this?
    '#default_value' => isset($element['#default_value'][0]['openlayers_wkt']) ? $element['#default_value'][0]['openlayers_wkt'] : NULL,
    '#type_name' => $element['#type_name'],
    '#delta' => $element['#delta'],
    '#columns' => $element['#columns'],
  );

  // Settings to show/hide WKT field.  Because of how
  // drupal_add_js merges arrays (specifically PHP),
  // we only send the text stuff once.
  static $sent = FALSE;
  if (!$sent) {
    drupal_add_js(array(
      'openlayers_cck' => array(
        'wkt_hide' => array(
          'text_show' => t('Show WKT field'),
          'text_hide' => t('Hide WKT field'),
        ),
      ),
    ), 'setting');
    $sent = TRUE;
  }
  $field_id = str_replace('_', '-', $field_name);
  drupal_add_js(array(
    'openlayers_cck' => array(
      'wkt_hide' => array(
        'fields' => array(
          $field_id => $field_id,
        ),
      ),
    ),
  ), 'setting');
  drupal_add_js(drupal_get_path('module', 'openlayers_cck') . '/js/openlayers_cck.js');

  // 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;
}