You are here

function nodereference_field in Content Construction Kit (CCK) 6

Same name and namespace in other branches
  1. 5 nodereference.module \nodereference_field()
  2. 6.3 modules/nodereference/nodereference.module \nodereference_field()
  3. 6.2 modules/nodereference/nodereference.module \nodereference_field()

Implementation of hook_field().

File

modules/nodereference/nodereference.module, line 158
Defines a field type for referencing one node from another.

Code

function nodereference_field($op, &$node, $field, &$items, $teaser, $page) {
  switch ($op) {
    case 'validate':
      $refs = _nodereference_potential_references($field, TRUE);
      foreach ($items as $delta => $item) {
        if (is_array($item) && !empty($item['error_field'])) {
          $error_field = $item['error_field'];
          unset($item['error_field']);
          if (!empty($item['nid'])) {
            if (!in_array($item['nid'], array_keys($refs))) {
              form_set_error($error_field, t('%name : This post can\'t be referenced.', array(
                '%name' => t($field['widget']['label']),
              )));
            }
          }
        }
      }
      return $items;
  }
}