You are here

function location_cck_field in Location 7.4

Same name and namespace in other branches
  1. 5.3 contrib/location_cck/location_cck.module \location_cck_field()
  2. 6.3 contrib/location_cck/location_cck.module \location_cck_field()
  3. 7.5 contrib/location_cck/location_cck.module \location_cck_field()
  4. 7.3 contrib/location_cck/location_cck.module \location_cck_field()

Implementation of hook_field(). @@@ GONE IN D7, move to hooks above...

File

contrib/location_cck/location_cck.module, line 173
Defines location field type.

Code

function location_cck_field($op, &$node, $field, &$items, $teaser, $page) {
  switch ($op) {
    case 'insert':
    case 'update':

      // Store instances of locations by field name and vid.
      $criteria = array(
        'genid' => 'cck:' . $field['field_name'] . ':' . $node->vid,
        'vid' => $node->vid,
        'nid' => $node->nid,
      );
      location_save_locations($items, $criteria);

      // CCK automatically picks up the new lids and stores them in its own tables.
      break;
    case 'load':
      $locations = array();

      // Locations are being cached by CCK now. Load the full location.
      foreach ($items as $item) {
        $locations[] = location_load_location($item['lid']);
      }
      return array(
        $field['field_name'] => $locations,
      );
    case 'sanitize':

      // Get the location information for the lid if it hasn't already been
      // loaded (in the hook_field() load $op using location_load_location()).
      // This is necessary for Views and any other modules that use the
      // content_format() function to render CCK fields because content_format()
      // doesn't call the "load" $op.
      foreach ($items as $delta => $item) {
        if (!isset($item['latitude'])) {
          $items[$delta] = array_merge($items[$delta], location_load_location($item['lid']));
        }
      }
      break;
    case 'delete':

      // Use the CCK storage to figure out the vids that need to be deleted,
      // and clean up all the applicable references.
      $db_info = content_database_info($field);
      $result = db_query('SELECT vid FROM {' . $db_info['table'] . '} WHERE nid = %d', $node->nid);
      while ($row = db_fetch_object($result)) {
        $genid = 'cck:' . $field['field_name'] . ':' . $row->vid;
        $locs = array();
        location_save_locations($locs, array(
          'genid' => $genid,
        ));
      }
      break;
    case 'delete revision':
      $genid = 'cck:' . $field['field_name'] . ':' . $node->vid;
      $locs = array();
      location_save_locations($locs, array(
        'genid' => $genid,
      ));
      break;
  }
}