You are here

function phonefield_field_validate in Phone Field 7

Implements hook_field_validate().

File

./phonefield.module, line 176
Hooks for a module that defines a simple phone number field type.

Code

function phonefield_field_validate($entity_type, $entity, $field, $instance, $langcode, $items, &$errors) {
  if (empty($entity)) {

    // Do not validate field config.
    return;
  }
  $nophone = TRUE;
  foreach ($items as $item) {
    $phonenumber = trim($item['phonenumber']);
    if (!empty($phonenumber)) {
      $nophone = FALSE;
      break;
    }
  }
  if ($instance['required'] && $nophone) {
    $errors[$field['field_name']][$langcode][0][] = array(
      'error' => 'phonefield_required',
      'message' => t('A phone number is required.'),
      'error_element' => array(
        'linklabel' => FALSE,
        'phonenumber' => TRUE,
      ),
    );
  }
}