You are here

function _brightcove_create_form_callback in Brightcove Video Connect 7.3

Same name and namespace in other branches
  1. 7.4 brightcove.module \_brightcove_create_form_callback()
  2. 7.5 brightcove.module \_brightcove_create_form_callback()

Create the new playlist.

_state

Parameters

$form:

Return value

bool|StdClass

1 call to _brightcove_create_form_callback()
ajax_create_playlist_dialog_close_callback in brightcove_field/brightcove_field.module

File

./brightcove.module, line 1160
Brightcove module is an integration layer between any modules using Brightcove API. It makes all necessary checks for the API and makes settings available to the user.

Code

function _brightcove_create_form_callback(&$form, $form_state) {
  $metadata = array();
  $keys_to_send = array(
    'name',
    'shortDescription',
  );
  foreach ($keys_to_send as $key) {
    $metadata[$key] = $form_state['values'][$key];
  }
  if ($form_state['values']['type'] == BRIGHTCOVE_PLAYLIST_TYPE_MANUAL) {
    $metadata['playlistType'] = 'explicit';
    $videos = drupal_explode_tags($form_state['values']['videos']);
    foreach ($videos as $video) {

      // Parse the video id.
      preg_match('/\\[id:(?P<videoid>\\d+)\\]/', $video, $matches);
      $metadata['videoIds'][] = $matches['videoid'];
    }
  }
  else {
    $metadata['tagInclusionRule'] = $form_state['values']['tagInclusionRule'];
    $metadata['playlistType'] = $form_state['values']['playlistType'];
    $metadata['filterTags'] = drupal_explode_tags($form_state['values']['filterTags']);
  }
  $id = brightcove_add_playlist($metadata);

  // We need to cache it and save it to session.
  // Brightcove Media API doesn't clear its cache when a new
  // playlist is created, therefore the node save would fail.
  $_SESSION['brightcove']['playlist'][$id] = $id;

  // Invalidate BC cache
  brightcove_invalidate_cache('brightcove:playlist:list', TRUE);
  return $id;
}