You are here

vefl.module in Views exposed form layout 8.2

Same filename and directory in other branches
  1. 8.3 vefl.module
  2. 8 vefl.module
  3. 7 vefl.module

Module file for vefl.

File

vefl.module
View 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])) {
        $regions[$region_name][$field_name] = $form[$field_name];
        $regions[$region_name][$field_name]['#title'] = isset($form['#info']['filter-' . $field_name]) ? $form['#info']['filter-' . $field_name]['label'] : NULL;
      }
    }
  }
  $layoutPluginManager = \Drupal::service('plugin.manager.core.layout');
  $layout = $layoutPluginManager
    ->createInstance($configuration['layout']['id'], $configuration['layout']['settings']);
  $built = $layout
    ->build($regions);
  $variables['form'] = $built;
}

Functions

Namesort descending 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().