You are here

function ajax_brightcove_media_upload_callback in Brightcove Video Connect 7.7

Same name and namespace in other branches
  1. 7.2 brightcove_media/brightcove_media.module \ajax_brightcove_media_upload_callback()
  2. 7.3 brightcove_media/brightcove_media.module \ajax_brightcove_media_upload_callback()
  3. 7.4 brightcove_media/brightcove_media.module \ajax_brightcove_media_upload_callback()
  4. 7.6 brightcove_media/brightcove_media.module \ajax_brightcove_media_upload_callback()

Ajax callback for upload form

_state

Parameters

$form:

Return value

array|bool|stdClass Validated form with messages

1 string reference to 'ajax_brightcove_media_upload_callback'
brightcove_media_upload_form in brightcove_media/brightcove_media.module
Upload form for brightcove media.

File

brightcove_media/brightcove_media.module, line 624
This module provide the hook implementations for the integration with Media module.

Code

function ajax_brightcove_media_upload_callback($form, $form_state) {

  // Make sure it is not set, might be needed if a user changes mind after
  // upload and wants to upload another.
  _brightcove_media_session_value_set(BRIGHTCOVE_MEDIA_SESSION_VALUE_NAME_UPLOADED, NULL);
  $video_id = _brightcove_upload_form_callback($form['uploadform'], $form_state);
  if (empty($video_id) || is_bool($video_id) || !is_scalar($video_id)) {
    return $video_id;
  }
  $client_id = $form_state['values']['client'];
  $client = brightcove_client_load_or_default($client_id);

  /** @var \Brightcove\Object\Video\Video|null $video */
  $video = NULL;
  brightcove_try(function () use ($client, &$video, $video_id) {

    /** @var \Brightcove\API\CMS $cms */
    list($cms) = brightcove_create_classes($client);
    $video = $cms
      ->getVideo($video_id);
  });
  $uri = file_stream_wrapper_uri_normalize("brightcove://v/{$video_id}/a/{$client->account_id}");
  $file = file_uri_to_object($uri);
  $file->filename = $video
    ->getName();
  $file->filemime = 'media/brightcove';
  $file->type = 'video';
  if (!isset($file->fid)) {
    $file->fid = 0;
  }
  media_browser_build_media_item($file);
  _brightcove_media_session_value_set(BRIGHTCOVE_MEDIA_SESSION_VALUE_NAME_UPLOADED, $file);
  return [
    '#type' => 'ajax',
    '#commands' => [
      ajax_command_brightcove_media_upload($file),
    ],
  ];
}