You are here

public function FotoramaGalleryFormatter::settingsForm in Fotorama Gallery 8.2

Same name and namespace in other branches
  1. 8 src/Plugin/Field/FieldFormatter/FotoramaGalleryFormatter.php \Drupal\fotorama_gallery\Plugin\Field\FieldFormatter\FotoramaGalleryFormatter::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 ImageFormatter::settingsForm

File

src/Plugin/Field/FieldFormatter/FotoramaGalleryFormatter.php, line 135

Class

FotoramaGalleryFormatter
Plugin implementation of the 'fotorama_gallery display' formatter.

Namespace

Drupal\fotorama_gallery\Plugin\Field\FieldFormatter

Code

public function settingsForm(array $form, FormStateInterface $form_state) {
  $element = parent::settingsForm($form, $form_state);
  unset($element['image_link']);
  $url_options = [
    'attributes' => [
      'target' => '_blank',
    ],
  ];
  $base_path_doc = 'https://fotorama.io/docs/4';
  $dimensions = $this
    ->getSettings()['dimensions'];
  $others = $this
    ->getSettings()['others'];
  $autoplay = $this
    ->getSettings()['autoplay'];
  $navigation = $this
    ->getSettings()['navigation'];
  $transition = $this
    ->getSettings()['transition'];

  // Field groups.
  $element['dimensions'] = [
    '#type' => 'details',
    '#title' => $this
      ->t('Dimensions'),
    '#description' => Link::fromTextAndUrl($this
      ->t('Documentation: Dimensions'), Url::fromUri($base_path_doc . '/dimensions/', $url_options)),
  ];
  $element['dimensions']['ratio'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Ratio'),
    '#size' => 10,
    '#default_value' => isset($dimensions['ratio']) ? $dimensions['ratio'] : '',
    '#description' => $this
      ->t('Ex. 4/3 , 16/9'),
  ];
  $element['dimensions']['width'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('data-width'),
    '#size' => 10,
    '#default_value' => isset($dimensions['width']) ? $dimensions['width'] : '',
  ];
  $element['dimensions']['maxwidth'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('data-maxwidth'),
    '#size' => 10,
    '#default_value' => isset($dimensions['maxwidth']) ? $dimensions['maxwidth'] : '',
  ];
  $element['dimensions']['minwidth'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('data-minwidth'),
    '#size' => 10,
    '#default_value' => isset($dimensions['minwidth']) ? $dimensions['minwidth'] : '',
  ];
  $element['dimensions']['height'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('data-Height'),
    '#size' => 10,
    '#default_value' => isset($dimensions['height']) ? $dimensions['height'] : '',
  ];
  $element['dimensions']['maxheight'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('data-maxheight'),
    '#size' => 10,
    '#default_value' => isset($dimensions['maxheight']) ? $dimensions['maxheight'] : '',
  ];
  $element['dimensions']['minheight'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('data-minheight'),
    '#size' => 10,
    '#default_value' => isset($dimensions['minheight']) ? $dimensions['minheight'] : '',
  ];
  $element['others'] = [
    '#type' => 'details',
    '#title' => $this
      ->t('Others'),
  ];
  $element['others']['fit'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('data-fit'),
    '#options' => $this->fitOptions,
    '#default_value' => $others['fit'],
    '#description' => Link::fromTextAndUrl($this
      ->t('Documentation: data-fit'), Url::fromUri($base_path_doc . '/fit/', $url_options)),
  ];
  $element['others']['allowfullscreen'] = [
    '#type' => 'select',
    '#title' => 'data-allowfullscreen',
    '#options' => $this->allowFullScreenOptions,
    '#default_value' => isset($others['allowfullscreen']) ? $others['allowfullscreen'] : 'false',
    '#description' => Link::fromTextAndUrl($this
      ->t('Documentation: data-allowfullscreen'), Url::fromUri($base_path_doc . '/allowfullscreen/', $url_options)),
  ];
  $element['others']['loop'] = [
    '#type' => 'checkbox',
    '#title' => 'data-loop',
    '#default_value' => $others['loop'],
    '#description' => Link::fromTextAndUrl($this
      ->t('Documentation: data-loop'), Url::fromUri($base_path_doc . '/loop/', $url_options)),
  ];
  $element['others']['shuffle'] = [
    '#type' => 'checkbox',
    '#title' => 'data-shuffle',
    '#default_value' => $others['shuffle'],
    '#description' => Link::fromTextAndUrl($this
      ->t('Documentation: data-shuffle'), Url::fromUri($base_path_doc . '/shuffle/', $url_options)),
  ];
  $element['others']['keyboard'] = [
    '#type' => 'checkbox',
    '#title' => 'data-keyboard',
    '#default_value' => $others['keyboard'],
    '#description' => Link::fromTextAndUrl($this
      ->t('Documentation: data-keyboard'), Url::fromUri($base_path_doc . '/keyboard/', $url_options)),
  ];
  $element['others']['arrows'] = [
    '#type' => 'select',
    '#title' => 'data-arrows',
    '#options' => $this->arrowsOptions,
    '#default_value' => $others['arrows'],
    '#description' => Link::fromTextAndUrl($this
      ->t('Documentation: data-arrows'), Url::fromUri($base_path_doc . '/arrows-click-swipe/', $url_options)),
  ];
  $element['others']['click'] = [
    '#type' => 'checkbox',
    '#title' => 'data-click',
    '#default_value' => $others['click'],
    '#description' => Link::fromTextAndUrl($this
      ->t('Documentation: data-click'), Url::fromUri($base_path_doc . '/arrows-click-swipe/', $url_options)),
  ];
  $element['others']['swipe'] = [
    '#type' => 'checkbox',
    '#title' => 'data-swipe',
    '#default_value' => $others['swipe'],
    '#description' => Link::fromTextAndUrl($this
      ->t('Documentation: data-swipe'), Url::fromUri($base_path_doc . '/arrows-click-swipe/', $url_options)),
  ];
  $element['others']['trackpad'] = [
    '#type' => 'checkbox',
    '#title' => 'data-trackpad',
    '#default_value' => $others['trackpad'],
    '#description' => Link::fromTextAndUrl($this
      ->t('Documentation: data-trackpad'), Url::fromUri($base_path_doc . '/arrows-click-swipe/', $url_options)),
  ];
  $element['autoplay'] = [
    '#type' => 'details',
    '#title' => $this
      ->t('Autoplay'),
  ];
  $element['autoplay']['stopautoplayontouch'] = [
    '#type' => 'checkbox',
    '#title' => 'data-stopautoplayontouch',
    '#default_value' => $autoplay['stopautoplayontouch'],
    '#description' => Link::fromTextAndUrl($this
      ->t('Documentation: data-stopautoplayontouch'), Url::fromUri($base_path_doc . '/autoplay/', $url_options)),
  ];
  $element['navigation'] = [
    '#type' => 'details',
    '#title' => $this
      ->t('Navigation'),
  ];
  $element['navigation']['nav'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('data-nav'),
    '#options' => $this->navOptions,
    '#default_value' => $navigation['nav'],
    '#description' => Link::fromTextAndUrl($this
      ->t('Documentation: data-nav'), Url::fromUri($base_path_doc . '/thumbnails/', $url_options)),
  ];
  $element['navigation']['navposition'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('data-navposition'),
    '#options' => $this->navPositionOptions,
    '#default_value' => $navigation['navposition'],
    '#description' => Link::fromTextAndUrl($this
      ->t('Documentation: data-navposition'), Url::fromUri($base_path_doc . '/navigation-position/', $url_options)),
  ];
  $element['transition'] = [
    '#type' => 'details',
    '#title' => $this
      ->t('Transition'),
  ];
  $element['transition']['transition'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('data-transition'),
    '#options' => $this->transitionOptions,
    '#default_value' => $transition['transition'],
    '#description' => Link::fromTextAndUrl($this
      ->t('Documentation: data-transition'), Url::fromUri($base_path_doc . '/transition/', $url_options)),
  ];
  $element['transition']['clicktransition'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('data-clicktransition'),
    '#options' => $this->clickTransitionOptions,
    '#default_value' => isset($transition['clicktransition']) ? $transition['clicktransition'] : '',
    '#description' => Link::fromTextAndUrl($this
      ->t('Documentation: data-clicktransition'), Url::fromUri($base_path_doc . '/transition/', $url_options)),
  ];
  return $element;
}