You are here

function getlocations_fields_field_insert in Get Locations 7

Same name and namespace in other branches
  1. 7.2 modules/getlocations_fields/getlocations_fields.module \getlocations_fields_field_insert()

Implements hook_field_insert(). Define custom insert behavior for this module's field types.

Parameters

$entity_type: The type of $entity.

$entity: The entity for the operation.

$field: The field structure for the operation.

$instance: The instance structure for $field on $entity's bundle.

$langcode: The language associated with $items.

$items: $entity->{$field['field_name']}[$langcode], or an empty array if unset.

File

modules/getlocations_fields/getlocations_fields.module, line 210
getlocations_fields.module @author Bob Hutchinson http://drupal.org/user/52366 @copyright GNU GPL

Code

function getlocations_fields_field_insert($entity_type, $entity, $field, $instance, $langcode, &$items) {
  $settings = FALSE;
  if (isset($field['settings'])) {
    $settings = $field['settings'];
  }
  $settings['display_settings'] = getlocations_fields_get_display_settings($instance['display']['default']['settings']);
  if (!empty($items)) {
    foreach ($items as $key => $item) {
      if (empty($item['latitude']) || empty($item['longitude'])) {
        unset($items[$key]);
      }
    }
    $criteria = array();
    if ($entity_type == 'node') {
      $criteria = array(
        'field_name' => $field['field_name'],
        'vid' => $entity->vid,
        'nid' => $entity->nid,
      );
    }
    elseif ($entity_type == 'user' || $entity_type == 'profile2') {
      $criteria = array(
        'field_name' => $field['field_name'],
        'uid' => $entity->uid,
      );
    }
    elseif ($entity_type == 'comment') {

      //
      $criteria = array(
        'field_name' => $field['field_name'],
        'cid' => $entity->cid,
      );
    }
    elseif ($entity_type == 'taxonomy_term') {
      $criteria = array(
        'field_name' => $field['field_name'],
        'tid' => $entity->tid,
      );
    }
    if (!empty($criteria)) {
      $items = getlocations_fields_save_locations($items, $criteria, $settings, 'insert');
    }
  }
}