PagerWidgetBase.php in Better Exposed Filters 8.5
File
src/Plugin/better_exposed_filters/pager/PagerWidgetBase.php
View source
<?php
namespace Drupal\better_exposed_filters\Plugin\better_exposed_filters\pager;
use Drupal\better_exposed_filters\Plugin\BetterExposedFiltersWidgetBase;
use Drupal\better_exposed_filters\Plugin\BetterExposedFiltersWidgetInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
abstract class PagerWidgetBase extends BetterExposedFiltersWidgetBase implements BetterExposedFiltersWidgetInterface {
use StringTranslationTrait;
protected $pagerElements = [
'items_per_page',
'offset',
];
public function defaultConfiguration() {
return parent::defaultConfiguration() + [
'advanced' => [
'is_secondary' => FALSE,
],
];
}
public static function isApplicable($handler = NULL, array $options = []) {
return TRUE;
}
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$form = [];
$form['advanced']['is_secondary'] = [
'#type' => 'checkbox',
'#title' => $this
->t('This is a secondary option'),
'#default_value' => !empty($this->configuration['advanced']['is_secondary']),
'#states' => [
'visible' => [
':input[name="exposed_form_options[bef][general][allow_secondary]"]' => [
'checked' => TRUE,
],
],
],
'#description' => $this
->t('Places this element in the secondary options portion of the exposed form.'),
];
return $form;
}
public function exposedFormAlter(array &$form, FormStateInterface $form_state) {
$is_secondary = !empty($form['secondary']) && $this->configuration['advanced']['is_secondary'];
foreach ($this->pagerElements as $element) {
if (empty($form[$element])) {
continue;
}
if ($is_secondary) {
$this
->addElementToGroup($form, $form_state, $element, 'secondary');
}
$this
->addContext($form[$element]);
}
}
}