You are here

function _brightcove_playlist_form in Brightcove Video Connect 7.3

Same name and namespace in other branches
  1. 7.4 brightcove.playlist.inc \_brightcove_playlist_form()
  2. 7.5 brightcove.playlist.inc \_brightcove_playlist_form()
2 calls to _brightcove_playlist_form()
brightcove_field_create_form in brightcove_field/brightcove_field.module
Create form. Will return a form for one playlist item.
brightcove_playlist_edit_form in ./brightcove.playlist.inc
Playlist edit form.

File

./brightcove.playlist.inc, line 101
This file contains function over the brightcove playlist feature.

Code

function _brightcove_playlist_form(&$form, $form_state, $playlist = NULL) {
  $form['referenceId'] = array(
    '#type' => 'hidden',
    '#value' => isset($form_state['values']['referenceId']) ? $form_state['values']['referenceId'] : '',
  );
  $type_default = BRIGHTCOVE_PLAYLIST_TYPE_MANUAL;
  if (!is_null($playlist) && $playlist->playlistType != 'EXPLICIT') {
    $type_default = BRIGHTCOVE_PLAYLIST_TYPE_SMART;
  }
  $active_type = $type_default;
  if (!empty($form_state['values']['type'])) {
    if ($form_state['values']['type'] == BRIGHTCOVE_PLAYLIST_TYPE_MANUAL) {
      $active_type = BRIGHTCOVE_PLAYLIST_TYPE_MANUAL;
    }
    else {
      if ($form_state['values']['type'] == BRIGHTCOVE_PLAYLIST_TYPE_SMART) {
        $active_type = BRIGHTCOVE_PLAYLIST_TYPE_SMART;
      }
    }
  }
  $form['type'] = array(
    '#title' => t('Playlist type'),
    '#type' => 'select',
    '#default_value' => $type_default,
    '#ajax' => array(
      'callback' => 'brightcove_playlist_edit_form_ajax_callback',
      'wrapper' => 'brightcove-playlist-settings',
    ),
    '#options' => array(
      BRIGHTCOVE_PLAYLIST_TYPE_MANUAL => t('Manual'),
      BRIGHTCOVE_PLAYLIST_TYPE_SMART => t('Smart'),
    ),
  );
  $form['name'] = array(
    '#type' => 'textfield',
    '#title' => 'Name',
    '#default_value' => isset($playlist->name) ? $playlist->name : '',
  );
  $form['shortDescription'] = array(
    '#type' => 'textarea',
    '#title' => 'Short description',
    '#default_value' => isset($playlist->shortDescription) ? $playlist->shortDescription : '',
  );
  $form['settings'] = array(
    '#type' => 'container',
    '#id' => 'brightcove-playlist-settings',
  );
  if ($active_type == BRIGHTCOVE_PLAYLIST_TYPE_MANUAL) {
    $videos = NULL;
    if (!empty($playlist)) {
      foreach ($playlist->videos as $video) {
        $videos .= check_plain($video->name) . ' [id:' . $video->id . ']';
        if (end($playlist->videos)->id != $video->id) {
          $videos .= ', ';
        }
      }
    }
    $form['settings']['videos'] = array(
      '#type' => 'textfield',
      '#title' => 'Videos',
      '#default_value' => !is_null($videos) ? $videos : '',
      '#autocomplete_path' => 'brightcove/autocomplete/videos',
    );
  }
  else {
    if ($active_type == BRIGHTCOVE_PLAYLIST_TYPE_SMART) {
      $form['settings']['tagInclusionRule'] = array(
        '#type' => 'select',
        '#title' => t('Smart playlist settings'),
        '#field_suffix' => t('of the following'),
        '#default_value' => 'OR',
        '#options' => array(
          'OR' => t('Contain one or more'),
          'AND' => t('Contain all'),
        ),
      );
      $form['settings']['filterTags'] = array(
        '#type' => 'textfield',
        '#title' => t('Tags'),
        '#default_value' => isset($playlist->filterTags) ? drupal_implode_tags($playlist->filterTags) : '',
        '#description' => t('Videos will be automatically added to this Playlist
                           based on the following settings.'),
      );
      $form['settings']['playlistType'] = array(
        '#type' => 'select',
        '#title' => t('Playlist ordering'),
        '#options' => array(
          'OLDEST_TO_NEWEST' => t('Oldest to newest (by activation date)'),
          'NEWEST_TO_OLDEST' => t('Newest to oldest (by activation date)'),
          'START_DATE_OLDEST_TO_NEWEST' => t('Oldest to newest'),
          'START_DATE_NEWEST_TO_OLDEST' => t('Newest to Oldest'),
          'ALPHABETICAL' => t('Alphabetical (by video name)'),
          'PLAYS_TOTAL' => t('Total plays'),
          'PLAYS_TRAILING_WEEK' => t('Plays trailing week'),
        ),
        '#default_value' => isset($playlist->playlistType) ? $playlist->playlistType : '',
      );
    }
  }
}