You are here

function link_field in Link 6.2

Same name and namespace in other branches
  1. 5 link.module \link_field()
  2. 6 link.module \link_field()

Implementation of hook_field().

File

./link.module, line 214
Defines simple link field types.

Code

function link_field($op, &$node, $field, &$items, $teaser, $page) {
  module_load_include('inc', 'link');
  switch ($op) {
    case 'load':
      return _link_load($field, $items);
    case 'validate':
      $optional_field_found = FALSE;
      if (!isset($field['validate_url']) || $field['validate_url'] !== 0) {
        foreach ($items as $delta => $value) {
          _link_validate($items[$delta], $delta, $field, $node, $optional_field_found);
        }
      }
      if ($field['url'] === 'optional' && $field['title'] === 'optional' && $field['required'] && !$optional_field_found) {
        form_set_error($field['field_name'] . '][0][title', t('At least one title or URL must be entered.'));
      }
      break;
    case 'presave':
    case 'update':
      foreach ($items as $delta => $value) {
        _link_process($items[$delta], $delta, $field, $node);
      }
      break;
    case 'sanitize':
      foreach ($items as $delta => $value) {
        _link_sanitize($items[$delta], $delta, $field, $node);
      }
      break;
  }
}