You are here

function brightcove_field_field_validate in Brightcove Video Connect 7.4

Same name and namespace in other branches
  1. 7.2 brightcove_field/brightcove_field.module \brightcove_field_field_validate()
  2. 7.3 brightcove_field/brightcove_field.module \brightcove_field_field_validate()
  3. 7.5 brightcove_field/brightcove_field.module \brightcove_field_field_validate()

Implements hook_field_validate().

File

brightcove_field/brightcove_field.module, line 339
Brightcove field module provides a Content Construction Kit module to developers, allowing them to browse videos in their Brightcove Studio and upload them.

Code

function brightcove_field_field_validate($entity_type, $entity, $field, $instance, $langcode, $items, &$errors) {
  switch ($instance['widget']['type']) {
    case BRIGHTCOVE_VIDEO_WIDGET:
      foreach ($items as $delta => $item) {
        if (!empty($item['brightcove_id'])) {
          $video = brightcove_video_load($item['brightcove_id']);
          if (empty($video->id) && empty($_SESSION['brightcove']['video'][$item['brightcove_id']])) {
            $errors[$field['field_name']][$langcode][$delta][] = array(
              'error' => 'brightcove_field',
              'message' => t('%name: invalid video.', array(
                '%name' => t(isset($field['widget']['label']) ? $field['widget']['label'] : ''),
              )),
            );
          }
        }
      }
      break;
    case BRIGHTCOVE_PLAYLIST_WIDGET:
      foreach ($items as $delta => $item) {
        if (!empty($item['brightcove_id'])) {
          $video = brightcove_playlist_load($item['brightcove_id']);
          if (empty($video->id) && empty($_SESSION['brightcove']['playlist'][$item['brightcove_id']])) {
            $errors[$field['field_name']][$langcode][$delta][] = array(
              'error' => 'brightcove_field',
              'message' => t('%name: invalid playlist.', array(
                '%name' => t(isset($field['widget']['label']) ? $field['widget']['label'] : ''),
              )),
            );
          }
        }
      }
      break;
  }
}