You are here

function brightcove_field_browser_playlist_validate in Brightcove Video Connect 7.3

Same name and namespace in other branches
  1. 7.4 brightcove_field/brightcove_field.module \brightcove_field_browser_playlist_validate()
  2. 7.5 brightcove_field/brightcove_field.module \brightcove_field_browser_playlist_validate()

Validate callback for the playlist field.

1 string reference to 'brightcove_field_browser_playlist_validate'
_brightcove_field_playlist_widget_form in brightcove_field/brightcove_field.playlist.inc

File

brightcove_field/brightcove_field.module, line 933
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_playlist_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.
      $playlist = brightcove_playlist_load($id);
      if (empty($playlist) && empty($_SESSION['brightcove']['playlist'][$id])) {
        form_error($element, t('%name: Found no valid playlist with that name.', array(
          '%name' => t($element['#title']),
        )));
      }
    }
    else {
      $result = brightcove_field_get_matched_playlists($value);
      if (count($result) > 1) {

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

        // No video found.
        form_error($element, t('%name: Found no valid playlist with that name.', array(
          '%name' => t($element['#title']),
        )));
      }
      else {
        $id = $result[0]->id;
      }
    }
  }
  form_set_value($element, $id, $form_state);
}