You are here

public function BootstrapBasicImageGalleryFormatter::settingsForm in Bootstrap Basic Image Gallery 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/BootstrapBasicImageGalleryFormatter.php, line 285

Class

BootstrapBasicImageGalleryFormatter
Plugin implementation of the 'BootstrapBasicImageGalleryFormatter' formatter.

Namespace

Drupal\bootstrap_basic_image_gallery\Plugin\Field\FieldFormatter

Code

public function settingsForm(array $form, FormStateInterface $form_state) {
  $image_styles = image_style_options(FALSE);
  $elements = [];
  $elements['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,
    '#description' => $this
      ->t('Image style used for rendering the main image.'),
  ];
  $elements['thumbnails_per_row'] = [
    '#type' => 'number',
    '#title' => $this
      ->t('Thumbnails Per Row'),
    '#description' => $this
      ->t('Number of thumbnails displayed per row under the main image.'),
    '#min' => 0,
    '#default_value' => $this
      ->getSetting('thumbnails_per_row'),
  ];
  $elements['thumbnail_image_style'] = [
    '#title' => $this
      ->t('Thumbnail Image style'),
    '#type' => 'select',
    '#default_value' => $this
      ->getSetting('thumbnail_image_style'),
    '#empty_option' => $this
      ->t('None (original image)'),
    '#options' => $image_styles,
    '#description' => $this
      ->t('Image style used for rendering the thumbnails.'),
  ];
  $elements['modal_image_style'] = [
    '#title' => $this
      ->t('Modal Image style'),
    '#type' => 'select',
    '#default_value' => $this
      ->getSetting('modal_image_style'),
    '#empty_option' => $this
      ->t('None (original image)'),
    '#options' => $image_styles,
    '#description' => $this
      ->t('Image style used for rendering the image in the modal popup (on click).'),
  ];
  $elements['carousel_autorotate'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Autorotate Carousel?'),
    '#description' => $this
      ->t('Decides whether or not the carousel auto-rotates after opening.'),
    '#default_value' => $this
      ->getSetting('carousel_autorotate'),
  ];
  $elements['carousel_interval'] = [
    '#type' => 'number',
    '#title' => $this
      ->t('Autorotate Carousel Interval'),
    '#description' => $this
      ->t('The amount of time to delay (in milliseconds) between automatically cycling an image.'),
    '#default_value' => $this
      ->getSetting('carousel_interval'),
    '#states' => [
      'visible' => [
        ':input[name="fields[' . $this->fieldDefinition
          ->getName() . '][settings_edit_form][settings][carousel_autorotate]"]' => [
          'checked' => TRUE,
        ],
      ],
    ],
  ];
  $elements['lazyload'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Lazy Load Images?'),
    '#description' => $this
      ->t('Decides whether or not the images in the popup will be lazy loaded. If yes, the images will not be loaded by the user until they are viewed. This speeds up page loading time.'),
    '#default_value' => $this
      ->getSetting('lazyload'),
  ];
  return $elements;
}