You are here

public function LinksWidget::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

src/Plugin/facets/widget/LinksWidget.php, line 137

Class

LinksWidget
The links widget.

Namespace

Drupal\facets\Plugin\facets\widget

Code

public function buildConfigurationForm(array $form, FormStateInterface $form_state, FacetInterface $facet) {
  $form = parent::buildConfigurationForm($form, $form_state, $facet);
  $options = [
    50,
    40,
    30,
    20,
    15,
    10,
    5,
    3,
  ];
  $form['soft_limit'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Soft limit'),
    '#default_value' => $this
      ->getConfiguration()['soft_limit'],
    '#options' => [
      0 => $this
        ->t('No limit'),
    ] + array_combine($options, $options),
    '#description' => $this
      ->t('Limit the number of displayed facets via JavaScript.'),
  ];
  $form['soft_limit_settings'] = [
    '#type' => 'container',
    '#title' => $this
      ->t('Soft limit settings'),
    '#states' => [
      'invisible' => [
        ':input[name="widget_config[soft_limit]"]' => [
          'value' => 0,
        ],
      ],
    ],
  ];
  $form['soft_limit_settings']['show_less_label'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Show less label'),
    '#description' => $this
      ->t('This text will be used for "Show less" link.'),
    '#default_value' => $this
      ->getConfiguration()['soft_limit_settings']['show_less_label'],
    '#states' => [
      'optional' => [
        ':input[name="widget_config[soft_limit]"]' => [
          'value' => 0,
        ],
      ],
    ],
  ];
  $form['soft_limit_settings']['show_more_label'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Show more label'),
    '#description' => $this
      ->t('This text will be used for "Show more" link.'),
    '#default_value' => $this
      ->getConfiguration()['soft_limit_settings']['show_more_label'],
    '#states' => [
      'optional' => [
        ':input[name="widget_config[soft_limit]"]' => [
          'value' => 0,
        ],
      ],
    ],
  ];
  $form['show_reset_link'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Show reset link'),
    '#default_value' => $this
      ->getConfiguration()['show_reset_link'],
  ];
  $form['reset_text'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Reset text'),
    '#default_value' => $this
      ->getConfiguration()['reset_text'],
    '#states' => [
      'visible' => [
        ':input[name="widget_config[show_reset_link]"]' => [
          'checked' => TRUE,
        ],
      ],
      'required' => [
        ':input[name="widget_config[show_reset_link]"]' => [
          'checked' => TRUE,
        ],
      ],
    ],
  ];
  $form['hide_reset_when_no_selection'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Hide reset link when no facet item is selected'),
    '#default_value' => $this
      ->getConfiguration()['hide_reset_when_no_selection'],
  ];
  return $form;
}