You are here

function brightcove_video_form in Brightcove Video Connect 7.6

Same name and namespace in other branches
  1. 7.7 brightcove.video.inc \brightcove_video_form()

Brightcove video entity form.

_state

Parameters

$form:

$video_entity:

null $entity_type:

null $bundle:

null $field_name:

Return value

mixed

4 string references to 'brightcove_video_form'
brightcove_entity_info in ./brightcove.module
Implements hook_entity_info().
brightcove_init in ./brightcove.module
Implements hook_init().
brightcove_video_edit in ./brightcove.video.inc
Menu callback to display a video edit form.
brightcove_video_upload in ./brightcove.video.inc
Menu callback to display the video upload dialog.

File

./brightcove.video.inc, line 453
Brightcove video related functions.

Code

function brightcove_video_form($form, &$form_state, $video_entity, $entity_type = NULL, $bundle = NULL, $field_name = NULL) {
  brightcove_load_lib();
  $form['#parent_entity_type'] = $entity_type;
  $form['#parent_bundle_name'] = $bundle;
  $form['#parent_field_name'] = $field_name;
  $client = $video_entity->client;

  /** @var \Brightcove\Object\Video\Video $video */
  $video = $video_entity->video;
  $video_id = $video
    ->getId();
  $form['#op'] = empty($video_id) ? 'upload' : 'edit';

  // Edit form
  if (!empty($video_id) && empty($form_state['values'])) {
    $form_state['values'] = [
      'title' => $video
        ->getName(),
      'short' => $video
        ->getDescription(),
      'long' => $video
        ->getLongDescription(),
      'reference_id' => $video
        ->getReferenceId(),
      'tags' => implode(', ', $video
        ->getTags()),
      'state' => $video
        ->getState(),
      'start_availability_date' => _brightcove_format_date($video
        ->getSchedule() ? $video
        ->getSchedule()
        ->getStartsAt() : NULL),
      'start_date' => $video
        ->getSchedule() ? $video
        ->getSchedule()
        ->getStartsAt() === '' ? 'immidiately' : 'date_set' : NULL,
      'end_availability_date' => _brightcove_format_date($video
        ->getSchedule() ? $video
        ->getSchedule()
        ->getEndsAt() : NULL),
      'end_date' => $video
        ->getSchedule() ? $video
        ->getSchedule()
        ->getEndsAt() === '' ? 'no_end_date' : 'date_set' : NULL,
      'linktext' => $video
        ->getLink() ? $video
        ->getLink()
        ->getText() : NULL,
      'linkurl' => $video
        ->getLink() ? $video
        ->getLink()
        ->getUrl() : NULL,
      'economics' => $video
        ->getEconomics(),
    ];
    foreach ($video
      ->getCustomFields() as $field => $value) {
      $form_state['values']["custom_field_{$field}"] = $value;
    }
  }
  drupal_prepare_form('brightcove_upload_form', $form, $form_state);
  $form += _brightcove_upload_form($form_state, $video_entity, $video_id);
  $form['#validate'][] = '_brightcove_upload_form_validate';

  // Add video
  if (empty($video_id)) {
    $form['#prefix'] = '<div id="dialog-upload-form">';
    $form['submit'] = [
      '#type' => 'submit',
      '#name' => 'submit-',
      '#default_value' => t('Attach'),
      '#ajax' => [
        'callback' => 'ajax_upload_video_dialog_close_callback',
        'wrapper' => 'dialog-upload-form',
      ],
    ];
    $form['#suffix'] = '</div>';
  }
  else {
    $form['#prefix'] = '<div id="dialog-edit-form">';
    $form['submit'] = [
      '#type' => 'submit',
      '#name' => 'submit-',
      '#default_value' => t('Save and Attach'),
      '#ajax' => [
        'callback' => 'ajax_edit_video_dialog_close_callback',
        'wrapper' => 'dialog-edit-form',
      ],
    ];
    $form['#suffix'] = '</div>';
  }
  $form['#attached'] = [
    'js' => [
      drupal_get_path('module', 'brightcove') . '/js/brightcove.js',
    ],
    'css' => [
      drupal_get_path('module', 'brightcove') . '/styles/upload.css',
      drupal_get_path('module', 'brightcove') . '/brightcove_field.upload.css',
    ],
  ];
  return $form;
}