You are here

public function Sliders::buildConfigurationForm in Better Exposed Filters 8.4

Same name and namespace in other branches
  1. 8.5 src/Plugin/better_exposed_filters/filter/Sliders.php \Drupal\better_exposed_filters\Plugin\better_exposed_filters\filter\Sliders::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 FilterWidgetBase::buildConfigurationForm

File

src/Plugin/better_exposed_filters/filter/Sliders.php, line 65

Class

Sliders
JQuery UI slider widget implementation.

Namespace

Drupal\better_exposed_filters\Plugin\better_exposed_filters\filter

Code

public function buildConfigurationForm(array $form, FormStateInterface $form_state) {

  /** @var \Drupal\views\Plugin\views\filter\FilterPluginBase $filter */
  $filter = $this->handler;
  $form = parent::buildConfigurationForm($form, $form_state);
  $form['min'] = [
    '#type' => 'number',
    '#title' => $this
      ->t('Range minimum'),
    '#default_value' => $this->configuration['min'],
    '#description' => $this
      ->t('The minimum allowed value for the jQuery range slider. It can be positive, negative, or zero and have up to 11 decimal places.'),
  ];
  $form['max'] = [
    '#type' => 'number',
    '#title' => $this
      ->t('Range maximum'),
    '#default_value' => $this->configuration['max'],
    '#description' => $this
      ->t('The maximum allowed value for the jQuery range slider. It can be positive, negative, or zero and have up to 11 decimal places.'),
  ];
  $form['step'] = [
    '#type' => 'number',
    '#title' => $this
      ->t('Step'),
    '#default_value' => $this->configuration['step'],
    '#description' => $this
      ->t('Determines the size or amount of each interval or step the slider takes between the min and max.') . '<br />' . $this
      ->t('The full specified value range of the slider (Range maximum - Range minimum) must be evenly divisible by the step.') . '<br />' . $this
      ->t('The step must be a positive number of up to 5 decimal places.'),
    '#min' => 0,
  ];
  $form['animate'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Animation speed'),
    '#options' => [
      self::ANIMATE_NONE => $this
        ->t('None'),
      self::ANIMATE_SLOW => $this
        ->t('Slow'),
      self::ANIMATE_NORMAL => $this
        ->t('Normal'),
      self::ANIMATE_FAST => $this
        ->t('Fast'),
      self::ANIMATE_CUSTOM => $this
        ->t('Custom'),
    ],
    '#default_value' => $this->configuration['animate'],
    '#description' => $this
      ->t('Whether to slide handle smoothly when user click outside handle on the bar.'),
  ];
  $form['animate_ms'] = [
    '#type' => 'number',
    '#title' => $this
      ->t('Animation speed in milliseconds'),
    '#default_value' => $this->configuration['animate_ms'],
    '#description' => $this
      ->t('The number of milliseconds to run the animation (e.g. 1000).'),
    '#states' => [
      'visible' => [
        ':input[name="exposed_form_options[bef][filter][' . $filter->field . '][configuration][animate]"]' => [
          'value' => self::ANIMATE_CUSTOM,
        ],
      ],
    ],
  ];
  $form['orientation'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Orientation'),
    '#options' => [
      self::ORIENTATION_HORIZONTAL => $this
        ->t('Horizontal'),
      self::ORIENTATION_VERTICAL => $this
        ->t('Vertical'),
    ],
    '#default_value' => $this->configuration['orientation'],
    '#description' => $this
      ->t('The orientation of the jQuery range slider.'),
  ];
  return $form;
}