You are here

public function SliderWidget::buildConfigurationForm in Facets 8

Provides a configuration form for this widget.

Parameters

array $form: A form API form array.

\Drupal\Core\Form\FormStateInterface $form_state: The form state object.

\Drupal\facets\FacetInterface $facet: The facet entitu.

Return value

array A renderable form array.

Overrides WidgetPluginBase::buildConfigurationForm

File

modules/facets_range_widget/src/Plugin/facets/widget/SliderWidget.php, line 92

Class

SliderWidget
The slider widget.

Namespace

Drupal\facets_range_widget\Plugin\facets\widget

Code

public function buildConfigurationForm(array $form, FormStateInterface $form_state, FacetInterface $facet) {
  $config = $this
    ->getConfiguration();
  $form = parent::buildConfigurationForm($form, $form_state, $facet);
  $form['prefix'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Value prefix'),
    '#size' => 5,
    '#default_value' => $config['prefix'],
  ];
  $form['suffix'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Value suffix'),
    '#size' => 5,
    '#default_value' => $config['suffix'],
  ];
  $form['min_type'] = [
    '#type' => 'radios',
    '#options' => [
      'fixed' => $this
        ->t('Fixed value'),
      'search_result' => $this
        ->t('Based on search result'),
    ],
    '#title' => $this
      ->t('Minimum value type'),
    '#default_value' => $config['min_type'],
  ];
  $form['min_value'] = [
    '#type' => 'number',
    '#title' => $this
      ->t('Minimum value'),
    '#default_value' => $config['min_value'],
    '#size' => 10,
    '#states' => [
      'visible' => [
        'input[name="widget_config[min_type]"]' => [
          'value' => 'fixed',
        ],
      ],
    ],
  ];
  $form['max_type'] = [
    '#type' => 'radios',
    '#options' => [
      'fixed' => $this
        ->t('Fixed value'),
      'search_result' => $this
        ->t('Based on search result'),
    ],
    '#title' => $this
      ->t('Maximum value type'),
    '#default_value' => $config['max_type'],
  ];
  $form['max_value'] = [
    '#type' => 'number',
    '#title' => $this
      ->t('Maximum value'),
    '#default_value' => $config['max_value'],
    '#size' => 5,
    '#states' => [
      'visible' => [
        'input[name="widget_config[max_type]"]' => [
          'value' => 'fixed',
        ],
      ],
    ],
  ];
  $form['step'] = [
    '#type' => 'number',
    '#step' => 0.001,
    '#title' => $this
      ->t('slider step'),
    '#default_value' => $config['step'],
    '#size' => 2,
  ];
  return $form;
}