function template_preprocess_vefl_views_exposed_form in Views exposed form layout 8.3
Same name and namespace in other branches
- 8 vefl.module \template_preprocess_vefl_views_exposed_form()
 - 8.2 vefl.module \template_preprocess_vefl_views_exposed_form()
 
A theme preprocess function for views_exposed_form.
Adds $region_widgets array with separated by regions widgets.
1 string reference to 'template_preprocess_vefl_views_exposed_form'
- vefl_theme_registry_alter in ./
vefl.module  - Implements hook_theme_registry_alter().
 
File
- ./
vefl.module, line 34  - Module file for vefl.
 
Code
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;
}