You are here

public function BrightcoveVideoPlaylistForm::buildForm in Brightcove Video Connect 3.x

Same name and namespace in other branches
  1. 8.2 src/Form/BrightcoveVideoPlaylistForm.php \Drupal\brightcove\Form\BrightcoveVideoPlaylistForm::buildForm()
  2. 8 src/Form/BrightcoveVideoPlaylistForm.php \Drupal\brightcove\Form\BrightcoveVideoPlaylistForm::buildForm()

Form constructor.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The form structure.

Overrides EntityForm::buildForm

2 calls to BrightcoveVideoPlaylistForm::buildForm()
BrightcovePlaylistForm::buildForm in src/Form/BrightcovePlaylistForm.php
Form constructor.
BrightcoveVideoForm::buildForm in src/Form/BrightcoveVideoForm.php
Form constructor.
2 methods override BrightcoveVideoPlaylistForm::buildForm()
BrightcovePlaylistForm::buildForm in src/Form/BrightcovePlaylistForm.php
Form constructor.
BrightcoveVideoForm::buildForm in src/Form/BrightcoveVideoForm.php
Form constructor.

File

src/Form/BrightcoveVideoPlaylistForm.php, line 52

Class

BrightcoveVideoPlaylistForm
Base form controller for Video and Playlist forms.

Namespace

Drupal\brightcove\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $form = parent::buildForm($form, $form_state);

  /* @var $entity \Drupal\brightcove\Entity\BrightcoveVideoPlaylistCmsEntity */
  $entity = $this->entity;
  $triggering_element = $form_state
    ->getTriggeringElement();

  // Check for an updated version of the Video.
  if ($entity
    ->id() && empty($triggering_element)) {
    BrightcoveUtil::checkUpdatedVersion($entity);
  }
  if ($entity
    ->isNew()) {

    // Set default api client.
    if (!$form['api_client']['widget']['#default_value']) {
      $form['api_client']['widget']['#default_value'] = $this->defaultAPIClient;
    }

    // Update player list on client selection.
    $form['api_client']['widget']['#ajax'] = [
      'callback' => [
        self::class,
        'apiClientUpdateForm',
      ],
      'event' => 'change',
      'wrapper' => 'player-ajax-wrapper',
    ];

    // Add ajax wrapper for player.
    $form['player']['widget']['#prefix'] = '<div id="' . $form['api_client']['widget']['#ajax']['wrapper'] . '">';
    $form['suffix']['widget']['#suffix'] = '</div>';
  }
  else {

    // Disable api client selection after the playlist is created.
    $form['api_client']['widget']['#disabled'] = TRUE;
  }

  // Change none option's name.
  $form['player']['widget']['#options'] = self::getPlayerOptions($form, $form_state);
  return $form;
}