You are here

function _bef_preprocess_nested_elements in Better Exposed Filters 8.5

Same name and namespace in other branches
  1. 8.3 better_exposed_filters.module \_bef_preprocess_nested_elements()
  2. 8.4 includes/better_exposed_filters.theme.inc \_bef_preprocess_nested_elements()

Internal function to handled nested form elements.

Adds 'is_nested' and 'depth' $variables. Requires 'children' to be set in variables array before being called.

Parameters

array $variables: An associative array containing:

  • element: An associative array containing the exposed form element.
3 calls to _bef_preprocess_nested_elements()
template_preprocess_bef_checkboxes in includes/better_exposed_filters.theme.inc
Prepares variables for bef-checkboxes template.
template_preprocess_bef_links in includes/better_exposed_filters.theme.inc
Prepares variables for bef-links template.
template_preprocess_bef_radios in includes/better_exposed_filters.theme.inc
Prepares variables for bef-radios template.

File

includes/better_exposed_filters.theme.inc, line 304
Theme hooks, preprocessor, and suggestions.

Code

function _bef_preprocess_nested_elements(array &$variables) {

  // Provide a hierarchical info on the element children for the template to
  // render as a nested <ul>. Views prepends '-' characters for each level of
  // depth in the vocabulary. Store that information, but remove the hyphens as
  // we don't want to display them.
  $variables['is_nested'] = TRUE;
  $variables['depth'] = [];
  foreach ($variables['children'] as $child) {
    if ($child === 'All') {

      // For non-required filters, put the any/all option at the root.
      $variables['depth'][$child] = 0;

      // And don't change the text as it defaults to "- Any -" and we do not
      // want to remove the leading hyphens.
      continue;
    }
    $original = $variables['element'][$child]['#title'];
    $variables['element'][$child]['#title'] = ltrim($original, '-');
    $variables['depth'][$child] = strlen($original) - strlen($variables['element'][$child]['#title']);
  }
}