1 link.module link_field_validate($entity_type, $entity, $field, $instance, $langcode, $items, &$errors)

Implements hook_field_validate().


core/modules/link/link.module, line 261
Defines simple link field types.


function link_field_validate($entity_type, $entity, $field, $instance, $langcode, $items, &$errors) {
  // When setting a default value on the field instance settings form, $entity
  // will be NULL. Do not validate the default provided values, which allows
  // for default titles to be provided but not a URL (or vice-versa). Invalid
  // or partial URLs are also acceptable for default values.
  if (is_null($entity)) {

  // Validate each field individually. Populate the $optional_field_found
  // variable if any "required" values have been provided.
  $optional_field_found = FALSE;
  foreach ($items as $delta => $value) {
    _link_validate($items[$delta], $delta, $field, $entity, $instance, $langcode, $optional_field_found, $errors);

  // If no values were provided across all values but the field itself is
  // required, throw a validation error on the first field.
  if ($instance['settings']['url'] === 'optional' && $instance['settings']['title'] === 'optional' && $instance['required'] && !$optional_field_found) {
    $errors[$field['field_name']][$langcode][0][] = array(
      'error' => 'link_required',
      'message' => t('At least one title or URL must be entered.'),
      'error_element' => array('url' => FALSE, 'title' => TRUE),