You are here

public function Bxslider::settingsForm in BxSlider 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

1 call to Bxslider::settingsForm()
BxsliderThs::settingsForm in src/Plugin/Field/FieldFormatter/BxsliderThs.php
Returns a form to configure settings for the formatter.
1 method overrides Bxslider::settingsForm()
BxsliderThs::settingsForm in src/Plugin/Field/FieldFormatter/BxsliderThs.php
Returns a form to configure settings for the formatter.

File

src/Plugin/Field/FieldFormatter/Bxslider.php, line 161

Class

Bxslider
BxSlider.

Namespace

Drupal\bxslider\Plugin\Field\FieldFormatter

Code

public function settingsForm(array $form, FormStateInterface $form_state) {
  $elements = parent::settingsForm($form, $form_state);
  $settings = $this
    ->getSettings();
  $field_name = $this->fieldDefinition
    ->getName();
  $image_styles = image_style_options(FALSE);
  $elements['slider'] = [
    '#type' => 'fieldset',
    '#title' => $this
      ->t('BxSlider'),
    '#weight' => 0,
  ];
  $elements['slider']['image_style'] = [
    '#title' => $this
      ->t('Image style'),
    '#type' => 'select',
    '#default_value' => $settings['slider']['image_style'],
    '#empty_option' => $this
      ->t('None (original image)'),
    '#options' => $image_styles,
  ];
  $elements['slider']['description'] = [
    '#markup' => $this
      ->t('Visit <a href="@field-help" target="_blank">http://bxslider.com/options</a> for more information about bxSlider options.', [
      '@field-help' => 'http://bxslider.com/options',
    ]),
  ];
  $elements['slider']['general'] = [
    '#type' => 'details',
    '#title' => $this
      ->t('General'),
    '#weight' => 1,
    '#open' => FALSE,
  ];
  $elements['slider']['general']['mode'] = [
    '#title' => $this
      ->t('Mode'),
    '#type' => 'select',
    '#default_value' => $settings['slider']['general']['mode'],
    '#options' => [
      'horizontal' => 'horizontal',
      'vertical' => 'vertical',
      'fade' => 'fade',
    ],
  ];
  $elements['slider']['general']['speed'] = [
    '#title' => $this
      ->t('Speed'),
    '#type' => 'textfield',
    '#size' => 60,
    '#default_value' => $settings['slider']['general']['speed'],
  ];
  $elements['slider']['general']['slideMargin'] = [
    '#title' => $this
      ->t('slideMargin'),
    '#type' => 'textfield',
    '#size' => 60,
    '#default_value' => $settings['slider']['general']['slideMargin'],
  ];
  $elements['slider']['general']['startSlide'] = [
    '#title' => $this
      ->t('startSlide'),
    '#type' => 'textfield',
    '#size' => 60,
    '#default_value' => $settings['slider']['general']['startSlide'],
  ];
  $elements['slider']['general']['randomStart'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('randomStart'),
    '#default_value' => $settings['slider']['general']['randomStart'],
  ];
  $elements['slider']['general']['infiniteLoop'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('infiniteLoop'),
    '#default_value' => $settings['slider']['general']['infiniteLoop'],
  ];
  $elements['slider']['general']['hideControlOnEnd'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('hideControlOnEnd'),
    '#default_value' => $settings['slider']['general']['hideControlOnEnd'],
  ];
  $elements['slider']['general']['easing'] = [
    '#title' => $this
      ->t('easing'),
    '#type' => 'textfield',
    '#size' => 60,
    '#default_value' => $settings['slider']['general']['easing'],
  ];
  $elements['slider']['general']['captions'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('captions'),
    '#default_value' => $settings['slider']['general']['captions'],
  ];
  $elements['slider']['general']['ticker'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('ticker'),
    '#default_value' => $settings['slider']['general']['ticker'],
  ];
  $elements['slider']['general']['tickerHover'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('tickerHover'),
    '#default_value' => $settings['slider']['general']['tickerHover'],
  ];
  $elements['slider']['general']['adaptiveHeight'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('adaptiveHeight'),
    '#default_value' => $settings['slider']['general']['adaptiveHeight'],
  ];
  $elements['slider']['general']['adaptiveHeightSpeed'] = [
    '#title' => $this
      ->t('adaptiveHeightSpeed'),
    '#type' => 'textfield',
    '#size' => 60,
    '#default_value' => $settings['slider']['general']['adaptiveHeightSpeed'],
  ];
  $elements['slider']['general']['video'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('video'),
    '#default_value' => $settings['slider']['general']['video'],
  ];
  $elements['slider']['general']['responsive'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('responsive'),
    '#default_value' => $settings['slider']['general']['responsive'],
  ];
  $elements['slider']['general']['useCSS'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('useCSS'),
    '#default_value' => $settings['slider']['general']['useCSS'],
  ];
  $elements['slider']['general']['preloadImages'] = [
    '#title' => $this
      ->t('preloadImages'),
    '#type' => 'select',
    '#default_value' => $settings['slider']['general']['preloadImages'],
    '#options' => [
      'all' => 'all',
      'visible' => 'visible',
    ],
  ];
  $elements['slider']['general']['touchEnabled'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('touchEnabled'),
    '#default_value' => $settings['slider']['general']['touchEnabled'],
  ];
  $elements['slider']['general']['swipeThreshold'] = [
    '#title' => $this
      ->t('swipeThreshold'),
    '#type' => 'textfield',
    '#size' => 60,
    '#default_value' => $settings['slider']['general']['swipeThreshold'],
  ];
  $elements['slider']['general']['oneToOneTouch'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('oneToOneTouch'),
    '#default_value' => $settings['slider']['general']['oneToOneTouch'],
  ];
  $elements['slider']['general']['preventDefaultSwipeX'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('preventDefaultSwipeX'),
    '#default_value' => $settings['slider']['general']['preventDefaultSwipeX'],
  ];
  $elements['slider']['general']['preventDefaultSwipeY'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('preventDefaultSwipeY'),
    '#default_value' => $settings['slider']['general']['preventDefaultSwipeY'],
  ];
  $elements['slider']['general']['wrapperClass'] = [
    '#title' => $this
      ->t('wrapperClass'),
    '#type' => 'textfield',
    '#size' => 60,
    '#default_value' => $settings['slider']['general']['wrapperClass'],
  ];
  $elements['slider']['pager'] = [
    '#type' => 'details',
    '#title' => $this
      ->t('Pager'),
    '#weight' => 2,
    '#open' => FALSE,
  ];
  $elements['slider']['pager']['pager'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('pager'),
    '#default_value' => $settings['slider']['pager']['pager'],
  ];
  $elements['slider']['pager']['pagerType'] = [
    '#title' => $this
      ->t('pagerType'),
    '#type' => 'select',
    '#default_value' => $settings['slider']['pager']['pagerType'],
    '#options' => [
      'full' => 'full',
      'short' => 'short',
    ],
    '#states' => [
      'enabled' => [
        ':input[name="fields[' . $field_name . '][settings_edit_form][settings][slider][pager][pager]"]' => [
          'checked' => TRUE,
        ],
      ],
    ],
  ];
  $elements['slider']['pager']['pagerShortSeparator'] = [
    '#title' => $this
      ->t('pagerShortSeparator'),
    '#type' => 'textfield',
    '#size' => 60,
    '#default_value' => $settings['slider']['pager']['pagerShortSeparator'],
    '#states' => [
      'enabled' => [
        ':input[name="fields[' . $field_name . '][settings_edit_form][settings][slider][pager][pager]"]' => [
          'checked' => TRUE,
        ],
      ],
    ],
  ];
  $elements['slider']['pager']['pagerSelector'] = [
    '#title' => $this
      ->t('pagerSelector'),
    '#type' => 'textfield',
    '#size' => 60,
    '#default_value' => $settings['slider']['pager']['pagerSelector'],
    '#states' => [
      'enabled' => [
        ':input[name="fields[' . $field_name . '][settings_edit_form][settings][slider][pager][pager]"]' => [
          'checked' => TRUE,
        ],
      ],
    ],
  ];
  $elements['slider']['pager']['pagerCustom_type_markup'] = [
    '#markup' => '<hr>',
  ];
  $elements['slider']['pager']['pagerCustom_type'] = [
    '#title' => $this
      ->t('Custom Pager'),
    '#type' => 'select',
    '#default_value' => $settings['slider']['pager']['pagerCustom_type'],
    '#options' => [
      'none' => 'None',
      'thumbnail_pager_method1' => 'Custom thumbnail pager - method 1',
      'thumbnail_pager_method2' => 'Custom thumbnail pager - method 2',
    ],
    '#description' => $this
      ->t('Select a predefined custom thumbnail pager.'),
    '#states' => [
      'enabled' => [
        ':input[name="fields[' . $field_name . '][settings_edit_form][settings][slider][pager][pager]"]' => [
          'checked' => TRUE,
        ],
      ],
    ],
  ];
  $elements['slider']['pager']['pagerCustom_image_style'] = [
    '#title' => $this
      ->t('Custom Pager - Image style'),
    '#type' => 'select',
    '#default_value' => $settings['slider']['pager']['pagerCustom_image_style'],
    '#empty_option' => $this
      ->t('None (thumbnail)'),
    '#options' => $image_styles,
    '#description' => $this
      ->t('Used only when some the "Custom Pager" option is selected.'),
    '#states' => [
      'enabled' => [
        ':input[name="fields[' . $field_name . '][settings_edit_form][settings][slider][pager][pagerCustom_type]"]' => [
          [
            'value' => 'thumbnail_pager_method1',
          ],
          [
            'value' => 'thumbnail_pager_method2',
          ],
        ],
        ':input[name="fields[' . $field_name . '][settings_edit_form][settings][slider][pager][pager]"]' => [
          'checked' => TRUE,
        ],
      ],
    ],
  ];
  $elements['slider']['controls'] = [
    '#type' => 'details',
    '#title' => $this
      ->t('Controls'),
    '#weight' => 3,
    '#open' => FALSE,
  ];
  $elements['slider']['controls']['controls'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('controls'),
    '#default_value' => $settings['slider']['controls']['controls'],
  ];
  $elements['slider']['controls']['nextText'] = [
    '#title' => $this
      ->t('nextText'),
    '#type' => 'textfield',
    '#size' => 60,
    '#default_value' => $settings['slider']['controls']['nextText'],
  ];
  $elements['slider']['controls']['prevText'] = [
    '#title' => $this
      ->t('prevText'),
    '#type' => 'textfield',
    '#size' => 60,
    '#default_value' => $settings['slider']['controls']['prevText'],
  ];
  $elements['slider']['controls']['nextSelector'] = [
    '#title' => $this
      ->t('nextSelector'),
    '#type' => 'textfield',
    '#size' => 60,
    '#default_value' => $settings['slider']['controls']['nextSelector'],
  ];
  $elements['slider']['controls']['prevSelector'] = [
    '#title' => $this
      ->t('prevSelector'),
    '#type' => 'textfield',
    '#size' => 60,
    '#default_value' => $settings['slider']['controls']['prevSelector'],
  ];
  $elements['slider']['controls']['autoControls'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('autoControls'),
    '#default_value' => $settings['slider']['controls']['autoControls'],
  ];
  $elements['slider']['controls']['startText'] = [
    '#title' => $this
      ->t('startText'),
    '#type' => 'textfield',
    '#size' => 60,
    '#default_value' => $settings['slider']['controls']['startText'],
  ];
  $elements['slider']['controls']['stopText'] = [
    '#title' => $this
      ->t('stopText'),
    '#type' => 'textfield',
    '#size' => 60,
    '#default_value' => $settings['slider']['controls']['stopText'],
  ];
  $elements['slider']['controls']['autoControlsCombine'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Auto'),
    '#default_value' => $settings['slider']['controls']['autoControlsCombine'],
  ];
  $elements['slider']['controls']['autoControlsSelector'] = [
    '#title' => $this
      ->t('autoControlsSelector'),
    '#type' => 'textfield',
    '#size' => 60,
    '#default_value' => $settings['slider']['controls']['autoControlsSelector'],
  ];
  $elements['slider']['auto'] = [
    '#type' => 'details',
    '#title' => $this
      ->t('Auto'),
    '#weight' => 4,
    '#open' => FALSE,
  ];
  $elements['slider']['auto']['auto'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Auto'),
    '#default_value' => $settings['slider']['auto']['auto'],
  ];
  $elements['slider']['auto']['pause'] = [
    '#title' => $this
      ->t('pause'),
    '#type' => 'textfield',
    '#size' => 60,
    '#default_value' => $settings['slider']['auto']['pause'],
  ];
  $elements['slider']['auto']['autoStart'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('autoStart'),
    '#default_value' => $settings['slider']['auto']['autoStart'],
  ];
  $elements['slider']['auto']['autoDirection'] = [
    '#title' => $this
      ->t('autoDirection'),
    '#type' => 'select',
    '#default_value' => $settings['slider']['auto']['autoDirection'],
    '#options' => [
      'next' => 'next',
      'prev' => 'prev',
    ],
  ];
  $elements['slider']['auto']['autoHover'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('autoHover'),
    '#default_value' => $settings['slider']['auto']['autoHover'],
  ];
  $elements['slider']['auto']['autoDelay'] = [
    '#title' => $this
      ->t('autoDelay'),
    '#type' => 'textfield',
    '#size' => 60,
    '#default_value' => $settings['slider']['auto']['autoDelay'],
  ];
  $elements['slider']['carousel'] = [
    '#type' => 'details',
    '#title' => $this
      ->t('Carousel'),
    '#weight' => 5,
    '#open' => FALSE,
  ];
  $elements['slider']['carousel']['minSlides'] = [
    '#title' => $this
      ->t('minSlides'),
    '#type' => 'textfield',
    '#size' => 60,
    '#default_value' => $settings['slider']['carousel']['minSlides'],
  ];
  $elements['slider']['carousel']['maxSlides'] = [
    '#title' => $this
      ->t('maxSlides'),
    '#type' => 'textfield',
    '#size' => 60,
    '#default_value' => $settings['slider']['carousel']['maxSlides'],
  ];
  $elements['slider']['carousel']['moveSlides'] = [
    '#title' => $this
      ->t('moveSlides'),
    '#type' => 'textfield',
    '#size' => 60,
    '#default_value' => $settings['slider']['carousel']['moveSlides'],
  ];
  $elements['slider']['carousel']['slideWidth'] = [
    '#title' => $this
      ->t('slideWidth'),
    '#type' => 'textfield',
    '#size' => 60,
    '#default_value' => $settings['slider']['carousel']['slideWidth'],
  ];

  // $colorbox_exist = module_exists('colorbox');.
  $colorbox_exist = \Drupal::moduleHandler()
    ->moduleExists('colorbox');
  $elements['colorbox'] = [
    '#type' => 'fieldset',
    '#title' => $this
      ->t('Colorbox'),
    '#weight' => 11,
    '#description' => $colorbox_exist ? $this
      ->t('For changing Colorbox styles and other options, please visit <a href=":link">:link</a>.', [
      ':link' => '/admin/config/media/colorbox',
    ]) : $this
      ->t("Please, enable the Colorbox module firstly."),
  ];
  if ($colorbox_exist) {
    $elements['colorbox']['enable'] = [
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Colorbox enable'),
      '#default_value' => $settings['colorbox']['enable'],
      '#disabled' => $colorbox_exist ? FALSE : TRUE,
    ];
    $elements['colorbox']['image_style'] = [
      '#title' => $this
        ->t('Colorbox Image style'),
      '#type' => 'select',
      '#default_value' => $settings['colorbox']['image_style'],
      '#empty_option' => $this
        ->t('None (original image)'),
      '#options' => $image_styles,
      '#disabled' => $colorbox_exist ? FALSE : TRUE,
    ];
    $gallery = [
      'none' => $this
        ->t('No gallery'),
      'field_post' => $this
        ->t('Per field'),
      'custom' => $this
        ->t('Custom (with tokens)'),
    ];
    $elements['colorbox']['colorbox_gallery'] = [
      '#title' => $this
        ->t('Gallery (image grouping)'),
      '#type' => 'select',
      '#default_value' => $settings['colorbox']['colorbox_gallery'],
      '#options' => $gallery,
      '#description' => $this
        ->t('How Colorbox should group the image galleries.'),
      '#disabled' => $colorbox_exist ? FALSE : TRUE,
    ];
    $elements['colorbox']['colorbox_gallery_custom'] = [
      '#title' => $this
        ->t('Custom gallery'),
      '#type' => 'textfield',
      '#default_value' => $settings['colorbox']['colorbox_gallery_custom'],
      '#description' => $this
        ->t('All images on a page with the same gallery value (rel attribute) will be grouped together. It must only contain lowercase letters, numbers, and underscores.'),
      '#required' => FALSE,
      '#states' => [
        'visible' => [
          ':input[name$="[settings_edit_form][settings][colorbox][colorbox_gallery]"]' => [
            'value' => 'custom',
          ],
        ],
      ],
      '#disabled' => $colorbox_exist ? FALSE : TRUE,
    ];
    if (\Drupal::moduleHandler()
      ->moduleExists('token')) {
      $elements['colorbox']['colorbox_token_gallery'] = [
        '#type' => 'details',
        '#title' => $this
          ->t('Replacement patterns'),
        '#theme' => 'token_tree_link',
        '#token_types' => [
          $form['#entity_type'],
          'file',
        ],
        '#states' => [
          'visible' => [
            ':input[name$="[settings_edit_form][settings][colorbox][colorbox_gallery]"]' => [
              'value' => 'custom',
            ],
          ],
        ],
        '#disabled' => $colorbox_exist ? FALSE : TRUE,
      ];
    }
    else {
      $elements['colorbox']['colorbox_token_gallery'] = [
        '#type' => 'details',
        '#title' => $this
          ->t('Replacement patterns'),
        '#description' => '<strong class="error">' . $this
          ->t('For token support the <a href="@token_url">token module</a> must be installed.', [
          '@token_url' => 'http://drupal.org/project/token',
        ]) . '</strong>',
        '#states' => [
          'visible' => [
            ':input[name$="[settings_edit_form][settings][colorbox][colorbox_gallery]"]' => [
              'value' => 'custom',
            ],
          ],
        ],
        '#disabled' => $colorbox_exist ? FALSE : TRUE,
      ];
    }
    $caption = [
      'none' => $this
        ->t('None'),
      'auto' => $this
        ->t('Automatic'),
      'title' => $this
        ->t('Title text'),
      'alt' => $this
        ->t('Alt text'),
      'entity_title' => $this
        ->t('Content title'),
      'custom' => $this
        ->t('Custom (with tokens)'),
    ];
    $elements['colorbox']['colorbox_caption'] = [
      '#title' => $this
        ->t('Caption'),
      '#type' => 'select',
      '#default_value' => $settings['colorbox']['colorbox_caption'],
      '#options' => $caption,
      '#description' => $this
        ->t('Automatic will use the first non-empty value out of the title, the alt text and the content title.'),
      '#disabled' => $colorbox_exist ? FALSE : TRUE,
    ];
    $elements['colorbox']['colorbox_caption_custom'] = [
      '#title' => $this
        ->t('Custom caption'),
      '#type' => 'textfield',
      '#default_value' => $settings['colorbox']['colorbox_caption_custom'],
      '#states' => [
        'visible' => [
          ':input[name$="[settings_edit_form][settings][colorbox][colorbox_caption]"]' => [
            'value' => 'custom',
          ],
        ],
      ],
      '#disabled' => $colorbox_exist ? FALSE : TRUE,
    ];
    if (\Drupal::moduleHandler()
      ->moduleExists('token')) {
      $elements['colorbox']['colorbox_token_caption'] = [
        '#type' => 'details',
        '#title' => $this
          ->t('Replacement patterns'),
        '#theme' => 'token_tree_link',
        '#token_types' => [
          $form['#entity_type'],
          'file',
        ],
        '#states' => [
          'visible' => [
            ':input[name$="[settings_edit_form][settings][colorbox][colorbox_caption]"]' => [
              'value' => 'custom',
            ],
          ],
        ],
        '#disabled' => $colorbox_exist ? FALSE : TRUE,
      ];
    }
    else {
      $elements['colorbox']['colorbox_token_caption'] = [
        '#type' => 'details',
        '#title' => $this
          ->t('Replacement patterns'),
        '#description' => '<strong class="error">' . $this
          ->t('For token support the <a href="@token_url">token module</a> must be installed.', [
          '@token_url' => 'http://drupal.org/project/token',
        ]) . '</strong>',
        '#states' => [
          'visible' => [
            ':input[name$="[settings_edit_form][settings][colorbox][colorbox_caption]"]' => [
              'value' => 'custom',
            ],
          ],
        ],
        '#disabled' => $colorbox_exist ? FALSE : TRUE,
      ];
    }
  }
  return $elements;
}