You are here

public function Slider::buildConfigurationForm in Pagerer 8

Same name and namespace in other branches
  1. 8.2 src/Plugin/pagerer/Slider.php \Drupal\pagerer\Plugin\pagerer\Slider::buildConfigurationForm()

Form constructor.

Plugin forms are embedded in other forms. In order to know where the plugin form is located in the parent form, #parents and #array_parents must be known, but these are not available during the initial build phase. In order to have these properties available when building the plugin form's elements, let this method return a form element that has a #process callback and build the rest of the form in the callback. By the time the callback is executed, the element's #parents and #array_parents properties will have been set by the form API. For more documentation on #parents and #array_parents, see \Drupal\Core\Render\Element\FormElement.

Parameters

array $form: An associative array containing the initial structure of the plugin form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form. Calling code should pass on a subform state created through \Drupal\Core\Form\SubformState::createForSubform().

Return value

array The form structure.

Overrides PagererStyleBase::buildConfigurationForm

File

src/Plugin/pagerer/Slider.php, line 25

Class

Slider
Pager style using a jQuery slider.

Namespace

Drupal\pagerer\Plugin\pagerer

Code

public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
  $config = parent::buildConfigurationForm($form, $form_state);
  unset($config['separators_container']);
  $config['plugin'] = [
    '#type' => 'details',
    '#title' => $this
      ->t("Slider"),
    '#description' => $this
      ->t("Slider options."),
  ];
  $config['plugin']['slider_width'] = [
    '#type' => 'number',
    '#title' => $this
      ->t("Width"),
    '#field_suffix' => $this
      ->t("em"),
    '#default_value' => $this->configuration['slider_width'],
    '#description' => $this
      ->t("The width of the slider bar. Expressed in 'em' for CSS styling. Leave blank to default to CSS settings."),
    '#required' => FALSE,
    '#size' => 3,
    '#maxlength' => 3,
    '#min' => 1,
  ];
  $options = [
    'tickmark',
    'timeout',
    'auto',
  ];
  $options = array_combine($options, $options);
  $config['plugin']['slider_action'] = [
    '#type' => 'select',
    '#title' => $this
      ->t("Action confirmation method"),
    '#options' => $options,
    '#default_value' => $this->configuration['slider_action'],
    '#description' => $this
      ->t("Select how the page relocation should be triggered after it has been selected through the slider. Options are: 'tickmark' (page relocation only occurs after user clicks a tickmark on the slider handle), 'timeout' (page relocation occurs after a grace time has elapsed), 'auto' (the timeout method is automatically selected based on the accuracy of the slider)."),
    '#required' => TRUE,
  ];
  $config['plugin']['slider_action_timeout'] = [
    '#type' => 'number',
    '#title' => $this
      ->t("Confirmation timeout"),
    '#default_value' => $this->configuration['slider_action_timeout'],
    '#description' => $this
      ->t("The grace time (in milliseconds) to wait before the page is relocated, in case 'timeout' confirmation method is selected. '0' will trigger relocation immediately."),
    '#size' => 5,
    '#maxlength' => 5,
    '#required' => TRUE,
    '#min' => 0,
  ];
  $options = [
    'yes',
    'no',
    'auto',
  ];
  $options = array_combine($options, $options);
  $config['plugin']['slider_navigation_icons'] = [
    '#type' => 'select',
    '#title' => $this
      ->t("Display navigation icons"),
    '#options' => $options,
    '#default_value' => $this->configuration['slider_navigation_icons'],
    '#description' => $this
      ->t("Select whether to display +/- navigation icons on the sides of the slider. Options are 'yes', 'no', 'auto' (the icons are automatically displayed based on the accuracy of the slider)."),
    '#required' => TRUE,
  ];
  return $config;
}