vefl.module in Views exposed form layout 8.3
Same filename and directory in other branches
Module file for vefl.
File
vefl.moduleView source
<?php
/**
* @file
* Module file for vefl.
*/
/**
* Implements hook_theme().
*/
function vefl_theme($existing, $type, $theme, $path) {
return [
'vefl_views_exposed_form' => [
'render element' => 'form',
'theme path' => $path,
],
];
}
/**
* Implements hook_theme_registry_alter().
*/
function vefl_theme_registry_alter(&$theme_registry) {
// Inserts default views preprocess function before vefl preprocess function.
$before = array_search('template_preprocess_vefl_views_exposed_form', $theme_registry['vefl_views_exposed_form']['preprocess functions']);
array_splice($theme_registry['vefl_views_exposed_form']['preprocess functions'], $before, 0, [
'template_preprocess_views_exposed_form',
]);
}
/**
* A theme preprocess function for views_exposed_form.
*
* Adds $region_widgets array with separated by regions widgets.
*/
function template_preprocess_vefl_views_exposed_form(&$variables) {
$form = $variables['form'];
$configuration = $form['#vefl_configuration'];
$regions = [];
foreach ($configuration['regions'] as $region_name => $field_names) {
$regions[$region_name] = [];
foreach ($field_names as $field_name) {
if (!empty($form['actions'][$field_name])) {
$regions[$region_name][$field_name] = $form['actions'][$field_name];
$regions[$region_name][$field_name]['#weight'] = $form['actions']['#weight'];
}
elseif (!empty($form[$field_name])) {
$form[$field_name]['#title'] = NULL;
$regions[$region_name][$field_name] = $form[$field_name];
if (empty($form[$field_name]['#title'])) {
$title = NULL;
foreach ($form['#info'] as $filter_name => $filter_info) {
// The $field_name always matches $filter_info['value'].
if (0 === strpos($filter_name, 'filter-') && $filter_info['value'] === $field_name && !empty($filter_info['label'])) {
$title = $filter_info['label'];
}
}
$regions[$region_name][$field_name]['#title'] = $title;
}
}
}
}
$layoutPluginManager = \Drupal::service('plugin.manager.core.layout');
$layout = $layoutPluginManager
->createInstance($configuration['layout']['id'], $configuration['layout']['settings']);
$built = $layout
->build($regions);
$variables['form'] = $built;
}
Functions
Name | Description |
---|---|
template_preprocess_vefl_views_exposed_form | A theme preprocess function for views_exposed_form. |
vefl_theme | Implements hook_theme(). |
vefl_theme_registry_alter | Implements hook_theme_registry_alter(). |