You are here

public function BaguetteboxFormatter::settingsForm in baguetteBox.js 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 ImageFormatter::settingsForm

File

src/Plugin/Field/FieldFormatter/BaguetteboxFormatter.php, line 48

Class

BaguetteboxFormatter
Plugin implementation of the 'baguettebox' formatter.

Namespace

Drupal\baguettebox\Plugin\Field\FieldFormatter

Code

public function settingsForm(array $form, FormStateInterface $form_state) {
  $settings = $this
    ->getSettings();
  $image_styles = image_style_options(FALSE);
  $element['image_style'] = [
    '#title' => $this
      ->t('Image style'),
    '#type' => 'select',
    '#default_value' => $this
      ->getSetting('image_style'),
    '#empty_option' => $this
      ->t('None (original image)'),
    '#options' => $image_styles,
  ];
  $element['baguette_image_style'] = $element['image_style'];
  $element['baguette_image_style']['#title'] = $this
    ->t('BaguetteBox image style (default)');
  $element['baguette_image_style']['#default_value'] = $this
    ->getSetting('baguette_image_style');
  $element['baguette_image_style_responsive'] = [
    '#type' => 'item',
    '#title' => $this
      ->t('BaguetteBox image style (responsive)'),
    '#tree' => TRUE,
  ];
  for ($i = 0; $i <= 4; $i++) {
    $element['baguette_image_style_responsive'][$i] = [
      '#type' => 'container',
      '#attributes' => [
        'class' => 'container-inline',
      ],
    ];
    $element['baguette_image_style_responsive'][$i]['width'] = [
      '#type' => 'number',
      '#title' => $this
        ->t('Width'),
      '#title_display' => 'none',
      '#placeholder' => $this
        ->t('Width'),
      '#min' => 1,
      '#max' => 99000,
      '#default_value' => $settings['baguette_image_style_responsive'][$i]['width'],
    ];
    $element['baguette_image_style_responsive'][$i]['image_style'] = [
      '#title' => $this
        ->t('Image style'),
      '#title_display' => 'none',
      '#type' => 'select',
      '#default_value' => $settings['baguette_image_style_responsive'][$i]['image_style'],
      '#empty_option' => $this
        ->t('None (original image)'),
      '#options' => $image_styles,
    ];
  }
  $element['animation'] = [
    '#title' => $this
      ->t('Animation'),
    '#type' => 'select',
    '#default_value' => $this
      ->getSetting('animation'),
    '#options' => $this
      ->animationOptions(),
  ];
  $element['captions_source'] = [
    '#title' => $this
      ->t('Captions source'),
    '#type' => 'select',
    '#default_value' => $this
      ->getSetting('captions_source'),
    '#options' => $this
      ->captionsSourceOptions(),
  ];
  $element['buttons'] = [
    '#title' => $this
      ->t('Display buttons'),
    '#type' => 'checkbox',
    '#default_value' => $this
      ->getSetting('buttons'),
  ];
  $element['fullscreen'] = [
    '#title' => $this
      ->t('Enable full screen mode'),
    '#type' => 'checkbox',
    '#default_value' => $this
      ->getSetting('fullscreen'),
  ];
  $element['hide_scrollbars'] = [
    '#title' => $this
      ->t('Hide scrollbars when gallery is displayed'),
    '#type' => 'checkbox',
    '#default_value' => $this
      ->getSetting('hide_scrollbars'),
  ];
  $element['inline'] = [
    '#title' => $this
      ->t('Display as inline elements'),
    '#type' => 'checkbox',
    '#default_value' => $this
      ->getSetting('inline'),
  ];
  return $element;
}