You are here

function gm3_field_field_insert in Google Maps API V3 7

Implementation of hook_field_insert().

1 call to gm3_field_field_insert()
gm3_field_field_update in gm3_field/gm3_field.module
Implementation of hook_field_update()

File

gm3_field/gm3_field.module, line 160

Code

function gm3_field_field_insert($entity_type, $entity, $field, $instance, $langcode, &$items) {
  switch ($field['type']) {
    case 'gm3_point':
      $new_items = array();
      if (is_string($items[0])) {

        // Strip point: from the string first.
        $items[0] = str_replace('point:', '', strtolower($items[0]));
        _gm3_field_get_array_from_points_string($items[0], $new_items);
      }
      if (count($items)) {
        _gm3_field_get_array_from_points_string($items[0]['map'], $new_items);
      }
      $items = $new_items;
      break;
    case 'gm3_rectangle':
    case 'gm3_polygon':
    case 'gm3_polyline':
      $new_items = array();
      if (is_string($items[0])) {
        $items[0] = str_replace(substr($field['type'], 4) . ':', '', strtolower($items[0]));
        _gm3_field_get_array_from_poly_string($items[0], $new_items, substr($field['type'], 4));
      }
      if (count($items)) {
        _gm3_field_get_array_from_poly_string($items[0]['map'], $new_items, substr($field['type'], 4));
      }
      $items = $new_items;
      break;
    case 'gm3_combination':
      $new_items = array();
      if (count($items)) {
        if (is_string($items[0])) {

          // Do something special here to attempt to magic stuff up!
          $lines = preg_split('/[\\n\\r]+/', $items[0]);
          $items = array(
            array(
              'map' => array(
                'children' => array(),
              ),
            ),
          );
          foreach ($lines as $line) {
            $line_parts = explode(':', $line);
            if (count($line_parts) > 1) {
              $type = "gm3_" . strtolower(array_shift($line_parts));
              $items[0]['map']['children'][$type][] = implode(':', $line_parts);
            }
          }
        }
        foreach ($items[0]['map']['children'] as $type => $value) {
          switch ($type) {
            case 'gm3_point':
              _gm3_field_get_array_from_points_string($value, $new_items, 'point');
              break;
            case 'gm3_rectangle':
            case 'gm3_polygon':
            case 'gm3_polyline':
              _gm3_field_get_array_from_poly_string($value, $new_items, substr($type, 4), TRUE);
              break;
            default:

              // Here we have a field that was not defined by this module, we use the
              // name of the module, plus the name of the type plus view to get the name
              // of the function to call
              // "{$field['module']}_{$field['type']}_view()"
              if (function_exists("{$type}_gm3_combination_insert")) {
                $function_name = "{$type}_gm3_combination_insert";
                $function_name($new_items, $value);
              }
              break;
          }
        }
      }
      $items = $new_items;
      break;
  }
}