public function BrightcoveAPIClientForm::form in Brightcove Video Connect 3.x
Same name and namespace in other branches
- 8.2 src/Form/BrightcoveAPIClientForm.php \Drupal\brightcove\Form\BrightcoveAPIClientForm::form()
- 8 src/Form/BrightcoveAPIClientForm.php \Drupal\brightcove\Form\BrightcoveAPIClientForm::form()
Gets the actual form array to be built.
Overrides EntityForm::form
See also
\Drupal\Core\Entity\EntityForm::processForm()
\Drupal\Core\Entity\EntityForm::afterBuild()
File
- src/
Form/ BrightcoveAPIClientForm.php, line 124
Class
- BrightcoveAPIClientForm
- Class BrightcoveAPIClientForm.
Namespace
Drupal\brightcove\FormCode
public function form(array $form, FormStateInterface $form_state) {
$form = parent::form($form, $form_state);
/** @var \Drupal\brightcove\Entity\BrightcoveAPIClient $brightcove_api_client */
$brightcove_api_client = $this->entity;
// Don't even try reporting the status/error message of a new client.
if (!$brightcove_api_client
->isNew()) {
try {
$brightcove_api_client
->authorizeClient();
$status = $brightcove_api_client
->getClientStatus() ? $this
->t('OK') : $this
->t('Error');
} catch (\Exception $e) {
$status = $this
->t('Error');
}
$form['status'] = [
'#type' => 'item',
'#title' => t('Status'),
'#markup' => $status,
];
if ($brightcove_api_client
->getClientStatus() == 0) {
$form['status_message'] = [
'#type' => 'item',
'#title' => t('Error message'),
'#markup' => $brightcove_api_client
->getClientStatusMessage(),
];
}
}
$form['label'] = [
'#type' => 'textfield',
'#title' => $this
->t('Label'),
'#maxlength' => 255,
'#default_value' => $brightcove_api_client
->label(),
'#description' => $this
->t('A label to identify the API Client (authentication credentials).'),
'#required' => TRUE,
];
$form['id'] = [
'#type' => 'machine_name',
'#default_value' => $brightcove_api_client
->id(),
'#machine_name' => [
'exists' => '\\Drupal\\brightcove\\Entity\\BrightcoveAPIClient::load',
],
'#disabled' => !$brightcove_api_client
->isNew(),
];
$form['client_id'] = [
'#type' => 'textfield',
'#title' => $this
->t('Brightcove API Client ID'),
'#description' => $this
->t('The Client ID of the Brightcove API Authentication credentials, available <a href=":link" target="_blank">here</a>.', [
':link' => 'https://studio.brightcove.com/products/videocloud/admin/oauthsettings',
]),
'#maxlength' => 255,
'#default_value' => $brightcove_api_client
->getClientId(),
'#required' => TRUE,
];
$form['secret_key'] = [
'#type' => 'textfield',
'#title' => $this
->t('Brightcove API Secret Key'),
'#description' => $this
->t('The Secret Key associated with the Client ID above, only visible once when Registering New Application.'),
'#maxlength' => 255,
'#default_value' => $brightcove_api_client
->getSecretKey(),
'#required' => TRUE,
];
$form['account_id'] = [
'#type' => 'textfield',
'#title' => $this
->t('Brightcove Account ID'),
'#description' => $this
->t('The number of one of the Brightcove accounts "selected for authorization" with the API Client above.'),
'#maxlength' => 255,
'#default_value' => $brightcove_api_client
->getAccountId(),
'#required' => TRUE,
];
$form['default_player'] = [
'#type' => 'select',
'#title' => $this
->t('Default player'),
'#options' => BrightcovePlayer::getList($brightcove_api_client
->id()),
'#default_value' => $brightcove_api_client
->getDefaultPlayer() ? $brightcove_api_client
->getDefaultPlayer() : BrightcoveAPIClient::DEFAULT_PLAYER,
'#required' => TRUE,
];
if ($brightcove_api_client
->isNew()) {
$form['default_player']['#description'] = t('The rest of the players will be available after saving.');
}
// Count BrightcoveAPIClients.
$api_clients_number = $this->queryFactory
->get('brightcove_api_client')
->count()
->execute();
$form['default_client'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Default API Client'),
'#description' => $this
->t('Enable to make this the default API Client.'),
'#default_value' => $api_clients_number == 0 || $this->config
->get('defaultAPIClient') == $brightcove_api_client
->id(),
];
return $form;
}