You are here

function youtube_field_validate in YouTube Field 7

Implements hook_field_validate().

File

./youtube.module, line 225

Code

function youtube_field_validate($entity_type, $entity, $field, $instance, $langcode, $items, &$errors) {
  foreach ($items as $delta => $item) {
    if (!empty($item['input'])) {
      $video_id = youtube_get_video_id($item['input']);
      if (!$video_id || strlen($video_id) > 15) {
        $errors[$field['field_name']][$langcode][$delta][] = array(
          'error' => 'youtube_invalid',
          'message' => t('Please provide a valid YouTube URL.'),
        );
      }
    }
  }
}