You are here

function location_cck_field in Location 5.3

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

Implementation of hook_field().

File

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

Code

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

      /*
      if (is_array($items)) {
        foreach ($items as $delta => $item) {
          $error_field = $field['field_name'] .']['. $delta .'][value';
          if ($item['value'] != '') {
            if (count($allowed_values) && !array_key_exists($item['value'], $allowed_values)) {
              form_set_error($error_field, t('Illegal value for %name.', array('%name' => t($field['widget']['label']))));
            }
          }
        }
      }
      */
      break;
    case 'insert':
    case 'update':

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

      // CCK automatically picks up the new lids and stores them in its own tables.
      break;

    /*
        case 'load':
          foreach ($items as $k => $v) {
            if ($v['lid']) {
              $items[$k] = location_load_location($v['lid']);
            }
          }
          break;
    */
    case 'delete':

      // Run through the revisions and clean up all applicable references.
      $result = db_query('SELECT vid FROM {node_revisions} 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;
  }
}