You are here

public function BrightcoveSubscriptionForm::buildForm in Brightcove Video Connect 8

Same name and namespace in other branches
  1. 8.2 src/Form/BrightcoveSubscriptionForm.php \Drupal\brightcove\Form\BrightcoveSubscriptionForm::buildForm()
  2. 3.x src/Form/BrightcoveSubscriptionForm.php \Drupal\brightcove\Form\BrightcoveSubscriptionForm::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 FormInterface::buildForm

File

src/Form/BrightcoveSubscriptionForm.php, line 25

Class

BrightcoveSubscriptionForm
Builds the form for Brightcove Subscription add, edit.

Namespace

Drupal\brightcove\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {

  /** @var \Drupal\brightcove\Entity\BrightcoveAPIClient[] $api_clients */
  $api_clients = BrightcoveAPIClient::loadMultiple();
  $api_client_options = [];
  foreach ($api_clients as $api_client) {
    $api_client_options[$api_client
      ->id()] = $api_client
      ->label();
  }
  $form['api_client_id'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Client'),
    '#options' => $api_client_options,
    '#required' => TRUE,
  ];
  if (empty($api_client_options)) {
    $form['api_client_id']['#empty_option'] = $this
      ->t('No API clients available');
  }
  elseif (empty($form['api_client_id']['#default'])) {
    $api_client_ids = array_keys($api_client_options);
    $default = reset($api_client_ids);
    $form['api_client_id']['#default_value'] = $default;
  }
  $form['endpoint'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Endpoint'),
    '#description' => $this
      ->t('The notifications endpoint.'),
    '#required' => TRUE,
  ];

  // Hard-code "video-change" event since it's the only one.
  $form['events'] = [
    '#type' => 'checkboxes',
    '#required' => TRUE,
    '#title' => 'Events',
    '#options' => [
      'video-change' => $this
        ->t('Video change'),
    ],
    '#default_value' => [
      'video-change',
    ],
    '#disabled' => TRUE,
  ];
  $form['actions']['submit'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Add'),
  ];
  return $form;
}