You are here

function video_embed_field_field_validate in Video Embed Field 7

Same name and namespace in other branches
  1. 7.2 video_embed_field.field.inc \video_embed_field_field_validate()

File

./video_embed_field.module, line 118

Code

function video_embed_field_field_validate($entity_type, $entity, $field, $instance, $langcode, $items, &$errors) {
  foreach ($items as $delta => $item) {
    if (!empty($item['video_url'])) {
      $item['video_url'] = trim($item['video_url']);
      if (stristr($item['video_url'], '.') && !stristr($item['video_url'], 'http://') && !stristr($item['video_url'], 'https://')) {
        $item['video_url'] = 'http://' . $item['video_url'];
      }
      $parts = parse_url($item['video_url']);
      if (!$parts || !isset($parts['host'])) {
        $errors[$field['field_name']][$langcode][$delta][] = array(
          'error' => t('Invalid Url'),
          'message' => t('Video: Invalid Video URL.', array(
            '%name' => $instance['label'],
          )),
        );
      }
      else {
        $host = $parts['host'];
        if (stripos($host, 'www.') > -1) {
          $host = substr($host, 4);
        }
        $handlers = video_embed_get_handlers();
        if (!isset($handlers[$host]['function']) || !function_exists($handlers[$host]['function'])) {
          $errors[$field['field_name']][$langcode][$delta][] = array(
            'error' => t('Unsupported Video Provider'),
            'message' => t('%name: This video provider is not currently supported.', array(
              '%name' => $instance['label'],
            )),
          );
        }
      }
    }
  }
}