You are here

function brightcove_field_browser_video_validate in Brightcove Video Connect 7.3

Same name and namespace in other branches
  1. 7.7 brightcove.module \brightcove_field_browser_video_validate()
  2. 7.4 brightcove_field/brightcove_field.module \brightcove_field_browser_video_validate()
  3. 7.5 brightcove_field/brightcove_field.module \brightcove_field_browser_video_validate()
  4. 7.6 brightcove.module \brightcove_field_browser_video_validate()

Validate callback for the video field.

2 string references to 'brightcove_field_browser_video_validate'
brightcove_field_browser_process in brightcove_field/brightcove_field.module
Brightcove field form that returns the actual field to the user. Parts of this and subsequent JS taken from Nodereference Explorer. Thanks!
_brightcove_field_video_widget_form in brightcove_field/brightcove_field.video.inc

File

brightcove_field/brightcove_field.module, line 886
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_browser_video_validate($element, &$form_state) {
  $id = '';
  $value = $element['#value'];
  if (!empty($value)) {

    // Assign ID to the value.
    // 231289 [id:72431493001]
    $id = brightcove_parse_id($value);
    if (is_numeric($id)) {

      // Matched ID, check if the video exists.
      $video = brightcove_video_load($id);

      // Check value in session variable for newly uploaded video.
      if (empty($video) && empty($_SESSION['brightcove']['video'][$id])) {
        form_error($element, t('%name: Found no valid video with that name. Please note that it might take several minutes after the video has been uploaded in Brightcove Studio to appear in the API.', array(
          '%name' => t($element['#title']),
        )));
      }
    }
    else {

      // Didn't match ID, try looking up the video text at BC.
      $bc = brightcove_initialize();
      $result = NULL;
      try {
        $result = $bc
          ->search('video', array(
          'all' => 'display_name:' . $value,
        ), array(
          'sort_by' => 'CREATION_DATE',
          'sort_order' => 'DESC',
        ));
      } catch (Exception $error) {
        form_error($element, t('There was a problem accessing Brightcove. Please try again'));
        watchdog('brightcove', 'Validating element with Brightcove failed', array(), WATCHDOG_ERROR);
      }
      if (count($result) > 1) {

        // This title is ambiguous.
        form_error($element, t('%name: Video title %title matched more than one video. In case of doubt, use text "title [id:ID_OF_THE_VIDEO]"', array(
          '%title',
          $value,
          '%name' => t($element['#title']),
        )));
      }
      elseif (count($result) == 0) {

        // No video found.
        form_error($element, t('%name: Found no valid video with that name. Please note that it might take several minutes after the video has been uploaded in Brightcove Studio to appear in the API.', array(
          '%name' => t($element['#title']),
        )));
      }
      else {
        $id = $result[0]->id;
      }
    }
  }
  form_set_value($element, $id, $form_state);
}