VeflBef.php in Views exposed form layout 8.2
File
modules/vefl_bef/src/Plugin/views/exposed_form/VeflBef.php
View source
<?php
namespace Drupal\vefl_bef\Plugin\views\exposed_form;
use Drupal\better_exposed_filters\Plugin\views\exposed_form\BetterExposedFilters;
use Drupal\vefl\Plugin\views\exposed_form\VeflTrait;
class VeflBef extends BetterExposedFilters {
use VeflTrait;
private function getRegionElements($layout_id, array $layouts = []) {
$element = [
'#prefix' => '<div id="edit-block-region-wrapper">',
'#suffix' => '</div>',
];
$types = [
'filters' => $this->view->display_handler
->getHandlers('filter'),
'actions' => $this->vefl
->getFormActions(),
];
$types['actions']['secondary'] = t('Secondary exposed form options');
$types['actions']['sort_bef_combine'] = t('Combine sort order with sort by');
$regions = [];
foreach ($layouts[$layout_id]
->getRegions() as $region_id => $region) {
$regions[$region_id] = $region['label'];
}
foreach ($types as $type => $fields) {
foreach ($fields as $id => $filter) {
if ($type == 'filters') {
if (!$filter->options['exposed']) {
continue;
}
elseif ($filter->options['is_grouped']) {
$id = $filter->options['group_info']['identifier'];
$label = $filter->options['group_info']['label'];
}
else {
$id = $filter->options['expose']['identifier'];
$label = $filter->options['expose']['label'];
}
}
else {
$label = $filter;
}
if (isset($filter->options['expose']['use_operator']) && $filter->options['expose']['use_operator']) {
$operator_id = $filter->options['expose']['operator_id'];
$element[$operator_id] = $this
->createSelectElementForVeflForm($operator_id, $this
->t('Expose operator') . ' - ' . $label, $regions);
}
$element[$id] = $this
->createSelectElementForVeflForm($id, $label, $regions);
if ($id == 'secondary') {
$element[$id]['#states'] = [
'visible' => [
':input[name="exposed_form_options[bef][general][allow_secondary]"]' => [
'checked' => TRUE,
],
],
];
}
if ($id == 'sort_bef_combine') {
$element[$id]['#states'] = [
'visible' => [
':input[name="exposed_form_options[bef][sort][advanced][combine]"]' => [
'checked' => TRUE,
],
],
];
}
}
}
return $element;
}
}
Classes
Name |
Description |
VeflBef |
Exposed form plugin that provides a better exposed filters form with layout. |