You are here

function nodereference_field in Content Construction Kit (CCK) 5

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

Implementation of hook_field().

File

./nodereference.module, line 112
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) {
        $error_field = isset($item['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;
  }
}