public function YouTubeFormatter::settingsForm in YouTube Field 8
Returns a form to configure settings for the formatter.
Invoked from \Drupal\field_ui\Form\EntityDisplayFormBase to allow administrators to configure the formatter. The field_ui module takes care of handling submitted form values.
Parameters
array $form: The form where the settings form is being included in.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
array The form elements for the formatter settings.
Overrides FormatterBase::settingsForm
File
- src/
Plugin/ Field/ FieldFormatter/ YouTubeFormatter.php, line 42
Class
- YouTubeFormatter
- Plugin implementation of the 'youtube_video' formatter.
Namespace
Drupal\youtube\Plugin\Field\FieldFormatterCode
public function settingsForm(array $form, FormStateInterface $form_state) {
$elements = parent::settingsForm($form, $form_state);
$elements['youtube_size'] = [
'#type' => 'select',
'#title' => $this
->t('YouTube video size'),
'#options' => youtube_size_options(),
'#default_value' => $this
->getSetting('youtube_size'),
];
$elements['youtube_width'] = [
'#type' => 'textfield',
'#title' => $this
->t('Width'),
'#size' => 10,
'#default_value' => $this
->getSetting('youtube_width'),
'#states' => [
'visible' => [
':input[name*="youtube_size"]' => [
'value' => 'custom',
],
],
],
];
$elements['youtube_height'] = [
'#type' => 'textfield',
'#title' => $this
->t('Height'),
'#size' => 10,
'#default_value' => $this
->getSetting('youtube_height'),
'#states' => [
'visible' => [
':input[name*="youtube_size"]' => [
'value' => 'custom',
],
],
],
];
$elements['youtube_autoplay'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Play video automatically when loaded (autoplay).'),
'#default_value' => $this
->getSetting('youtube_autoplay'),
];
$elements['youtube_mute'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Mute video by default when loaded (mute).'),
'#default_value' => $this
->getSetting('youtube_mute'),
];
$elements['youtube_loop'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Loop the playback of the video (loop).'),
'#default_value' => $this
->getSetting('youtube_loop'),
];
$elements['youtube_controls'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Always hide video controls (controls).'),
'#default_value' => $this
->getSetting('youtube_controls'),
];
$elements['youtube_autohide'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Hide video controls after play begins (autohide).'),
'#default_value' => $this
->getSetting('youtube_autohide'),
];
$elements['youtube_iv_load_policy'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Hide video annotations by default (iv_load_policy).'),
'#default_value' => $this
->getSetting('youtube_iv_load_policy'),
];
return $elements;
}