You are here

public function SoundcloudEmbedFormatter::settingsForm in Media entity Soundcloud 3.x

Same name and namespace in other branches
  1. 8.2 src/Plugin/Field/FieldFormatter/SoundcloudEmbedFormatter.php \Drupal\media_entity_soundcloud\Plugin\Field\FieldFormatter\SoundcloudEmbedFormatter::settingsForm()
  2. 8 src/Plugin/Field/FieldFormatter/SoundcloudEmbedFormatter.php \Drupal\media_entity_soundcloud\Plugin\Field\FieldFormatter\SoundcloudEmbedFormatter::settingsForm()

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/SoundcloudEmbedFormatter.php, line 39

Class

SoundcloudEmbedFormatter
Plugin implementation of the 'soundcloud_embed' formatter.

Namespace

Drupal\media_entity_soundcloud\Plugin\Field\FieldFormatter

Code

public function settingsForm(array $form, FormStateInterface $form_state) {
  $elements = parent::settingsForm($form, $form_state);
  $elements['type'] = [
    '#title' => $this
      ->t('Type'),
    '#type' => 'select',
    '#options' => [
      'visual' => $this
        ->t('Visual'),
      'classic' => $this
        ->t('Classic'),
    ],
    '#default_value' => $this
      ->getSetting('type'),
    '#description' => $this
      ->t('The type of embed.'),
  ];
  $elements['width'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Width'),
    '#default_value' => $this
      ->getSetting('width'),
    '#min' => 1,
    '#required' => TRUE,
    '#description' => $this
      ->t('Width of embedded player.'),
  ];
  $elements['height'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Height'),
    '#default_value' => $this
      ->getSetting('height'),
    '#min' => 1,
    '#required' => TRUE,
    '#description' => $this
      ->t('Height (px) of embedded player. Suggested values: 450 for the visual type and 166 for classic.'),
  ];
  $elements['options'] = [
    '#title' => $this
      ->t('Options'),
    '#type' => 'checkboxes',
    '#default_value' => $this
      ->getSetting('options'),
    '#options' => $this
      ->getEmbedOptions(),
  ];
  return $elements;
}