You are here

function _bef_preprocess_nested_elements in Better Exposed Filters 8.3

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

Internal function to provide information the templates for rendering nested elements. Adds 'is_nested' and 'depth' to $variables. Requires 'children' to be set in $variables before being called.

Parameters

array $variables:

3 calls to _bef_preprocess_nested_elements()
template_preprocess_bef_checkboxes in ./better_exposed_filters.module
template_preprocess_bef_links in ./better_exposed_filters.module
template_preprocess_bef_radios in ./better_exposed_filters.module

File

./better_exposed_filters.module, line 265
Allows the use of checkboxes, radio buttons or hidden fields for exposed Views filters.

Code

function _bef_preprocess_nested_elements(array &$variables) {
  if (empty($variables['element']['#bef_nested'])) {
    return;
  }

  // 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['isNested'] = 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']);
  }
}