public function MediaElementConfigForm::buildForm in MediaElement 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/ MediaElementConfigForm.php, line 79
Class
- MediaElementConfigForm
- Configuration form for MediaElement.js module.
Namespace
Drupal\mediaelement\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this
->config('mediaelement.settings');
// Create configurations for where the library is loaded from.
$library_config = $config
->get('library_settings');
$form['library_settings'] = [
'#type' => 'details',
'#title' => $this
->t('Library Settings'),
'#open' => TRUE,
];
$form['library_settings']['library_source'] = [
'#type' => 'radios',
'#title' => $this
->t('Library Source'),
'#options' => [
'local' => $this
->t('Local Download'),
'cdnjs' => $this
->t('CDN (Provided by CDNJS.com)'),
],
'#default_value' => $library_config['library_source'] ?? 'local',
'#required' => TRUE,
];
$form['library_settings']['cdnjs_settings'] = [
'#type' => 'fieldset',
'#title' => $this
->t('CDNJS Settings'),
'#states' => [
'visible' => [
':input[name="library_source"]' => [
'value' => 'cdnjs',
],
],
],
];
$version_options = $this
->getVersionList();
$form['library_settings']['cdnjs_settings']['library_version'] = [
'#type' => 'select',
'#title' => $this
->t('Library Version'),
'#options' => array_combine($version_options, $version_options),
'#default_value' => $library_config['cdnjs_settings']['library_version'] ?? $version_options[0],
];
// Global configuration items for player functionality.
$global_config = $config
->get('global_settings');
$form['global_settings'] = [
'#type' => 'fieldset',
'#title' => $this
->t('Global Settings'),
];
$form['global_settings']['attach_sitewide'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Enable MediaElement.js site wide'),
'#description' => $this
->t('Attach the MediaElement.js library throughtout the entire site. Any <code>audio</code> or <code>video</code> HTML tag will have the player applied to them.'),
'#default_value' => $global_config['attach_sitewide'] ?? FALSE,
'#weight' => 0,
];
// Configuration that applies to all types of players.
$player_config = $config
->get('global_settings.player_settings');
$form['global_settings']['player_settings'] = [
'#type' => 'details',
'#title' => $this
->t('General Player Settings'),
'#weight' => 1,
];
$form['global_settings']['player_settings']['class_prefix'] = [
'#type' => 'textfield',
'#title' => $this
->t('Class Prefix'),
'#description' => $this
->t('Class prefix for player elements.'),
'#default_value' => $player_config['class_prefix'] ?? '',
'#placeholder' => 'mejs__',
];
$form['global_settings']['player_settings']['set_dimensions'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Set Dimensions'),
'#description' => $this
->t('Set dimensions via JS instead of CSS.'),
'#default_value' => $player_config['set_dimensions'] ?? TRUE,
];
// Configuration for video players.
$video_settings = $config
->get('global_settings.video_settings');
$form['global_settings']['video_settings'] = [
'#type' => 'details',
'#title' => $this
->t('Video Player Settings'),
'#weight' => 2,
];
$form['global_settings']['video_settings']['default_video_width'] = [
'#type' => 'number',
'#title' => $this
->t('Default Video Width'),
'#description' => $this
->t('Default width if the <code><video></code> width is not specified'),
'#default_value' => $video_settings['default_video_width'] ?? '',
'#placeholder' => '480',
];
$form['global_settings']['video_settings']['default_video_height'] = [
'#type' => 'number',
'#title' => $this
->t('Default Video Height'),
'#description' => $this
->t('Default width if the <code><video></code> height is not specified'),
'#default_value' => $video_settings['default_video_height'] ?? '',
'#placeholder' => '270',
];
$form['global_settings']['video_settings']['video_width'] = [
'#type' => 'number',
'#title' => $this
->t('Video Width'),
'#description' => $this
->t('If set, overrides <code><video></code> width'),
'#default_value' => $video_settings['video_width'] ?? '',
'#placeholder' => '-1',
];
$form['global_settings']['video_settings']['video_height'] = [
'#type' => 'number',
'#title' => $this
->t('Video Height'),
'#description' => $this
->t('If set, overrides <code><video></code> height'),
'#default_value' => $video_settings['video_height'] ?? '',
'#placeholder' => '-1',
];
// Configuration for audio players.
$audio_settings = $config
->get('global_settings.audio_settings');
$form['global_settings']['audio_settings'] = [
'#type' => 'details',
'#title' => $this
->t('Audio Player Settings'),
'#weight' => 3,
];
$form['global_settings']['audio_settings']['default_audio_width'] = [
'#type' => 'number',
'#title' => $this
->t('Default Audio Width'),
'#description' => $this
->t('Default width if the <code><audio></code> width is not specified'),
'#default_value' => $audio_settings['default_audio_width'] ?? '',
'#placeholder' => '400',
];
$form['global_settings']['audio_settings']['default_audio_height'] = [
'#type' => 'number',
'#title' => $this
->t('Default Audio Height'),
'#description' => $this
->t('Default width if the <code><audio></code> height is not specified'),
'#default_value' => $audio_settings['default_audio_height'] ?? '',
'#placeholder' => '30',
];
$form['global_settings']['audio_settings']['audio_width'] = [
'#type' => 'number',
'#title' => $this
->t('Audio Width'),
'#description' => $this
->t('If set, overrides <code><audio></code> width'),
'#default_value' => $audio_settings['audio_width'] ?? '',
'#placeholder' => '-1',
];
$form['global_settings']['audio_settings']['audio_height'] = [
'#type' => 'number',
'#title' => $this
->t('Audio Height'),
'#description' => $this
->t('If set, overrides <code><audio></code> height'),
'#default_value' => $audio_settings['audio_height'] ?? '',
'#placeholder' => '-1',
];
$api_link = Link::fromTextAndUrl($this
->t('API Documentation'), Url::fromUri('https://github.com/mediaelement/mediaelement/blob/master/docs/api.md#mediaelementplayer'));
$form['global_settings']['api_link'] = [
'#markup' => $this
->t('<small>For a full explaination of configuration options, see the @api_link.</small>', [
'@api_link' => $api_link
->toString(),
]),
'#weight' => 10,
];
return parent::buildForm($form, $form_state);
}