public function JwplayerSettingsForm::buildForm in JW Player 8
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 ConfigFormBase::buildForm
File
- src/
Form/ JwplayerSettingsForm.php, line 37
Class
- JwplayerSettingsForm
- Configure search settings for this site.
Namespace
Drupal\jw_player\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this
->config('jw_player.settings');
$versions = [
6 => 6,
7 => 7,
8 => 8,
];
$url = 'https://dashboard.jwplayer.com/#/players/downloads';
$form['jw_player_version'] = array(
'#type' => 'select',
'#title' => $this
->t('Player version'),
'#options' => $versions,
'#default_value' => $config
->get('jw_player_version'),
'#description' => $this
->t('Select the version of JWPlayer you are using.'),
);
$form['jw_player_hosting'] = [
'#type' => 'radios',
'#title' => $this
->t('Hosting type'),
'#options' => [
'self' => $this
->t('Self-Hosted'),
'cloud' => $this
->t('Cloud-Hosted'),
],
'#default_value' => $config
->get('cloud_player_library_url') ? 'cloud' : 'self',
'#description' => $this
->t('Choose if JW Player will be downloaded and self-hosted, or the site will use JW Player\'s cloud-hosting service.'),
'#states' => [
'visible' => [
array_map(function ($version) {
return [
'select[name="jw_player_version"]' => [
'value' => $version,
],
];
}, array_keys($versions)),
],
],
];
$form['jw_player_key'] = array(
'#type' => 'textfield',
'#title' => $this
->t('Self-Hosted Player License Key'),
'#description' => $this
->t('Enter your key here. You can retrieve your license key from <a href="@url" target="_blank">your downloads page at jwplayer.com</a>.', array(
'@url' => $url,
)),
'#default_value' => $config
->get('jw_player_key'),
'#states' => [
'visible' => [
array_map(function ($version) {
return [
'select[name="jw_player_version"]' => [
'value' => $version,
],
':input[name="jw_player_hosting"]' => [
'value' => 'self',
],
];
}, array_keys($versions)),
],
],
);
$form['cloud_player_library_url'] = array(
'#type' => 'textfield',
'#title' => $this
->t('Cloud Player Library Url'),
'#description' => $this
->t('You can get the url for your cloud hosted player at <a href="@url" target="_blank">your downloads page at jwplayer.com</a>. After choosing your player, simply copy and enter the whole url from the field "Cloud Player Library Url" here. If you are using the cloud hosted player, the self hosted files will not be loaded.', array(
'@url' => $url,
)),
'#default_value' => $config
->get('cloud_player_library_url'),
'#states' => [
'visible' => [
array_map(function ($version) {
return [
'select[name="jw_player_version"]' => [
'value' => $version,
],
':input[name="jw_player_hosting"]' => [
'value' => 'cloud',
],
];
}, array_keys($versions)),
],
],
);
return parent::buildForm($form, $form_state);
}