New undefined index $options bug

Created on 8 May 2016, over 8 years ago
Updated 5 September 2024, 4 months ago

Running drupal 7.43 and better_exposed_filters 7.x-3.2-48-dev

I have a view in which I wished to rewrite the exposed filter values, leaving just 2 exposed, with different names. This is a date filter, so the filter list is 12 items long.

First off, there was no way of knowing what the original indices were without debugging the code. I tried:
0|new name
1|next name
but the code requires the actual values of the indices which are <, <= etc.
Without these indices, no joy.

Second, there seems to be an error in code where incorrect options are being called. Corrected code below. However, I have no idea of the affect of this change on anything else. I just needed to make this functionality work for me.

Beginning on line 1104 of better_exposed_filters_exposed_form_plugin.inc, my changes can be found after lines beginning with:

    foreach ($settings as $label => $options) {
      // Sanity check: Ensure this filter is an exposed filter.
      if (empty($filters[$label]) || !$filters[$label]->options['exposed']) {
        continue;
      }

      // Form element is designated by the element ID which is user-
      // configurable.
      $filter_key = 'filter-' . (!empty($filters[$label]->options['is_grouped']) ? $filters[$label]->options['group_info']['identifier'] : $label);
// LS 8 May 2016 correct bug that prevents renaming of values
      $filter_id = $form['#info'][$filter_key]['operator'];
//      $filter_id = $form['#info'][$filter_key]['value'];

      // Token replacement on BEF Description fields.
      if (!empty($options['more_options']['bef_filter_description'])) {
        // Collect replacement data.
        $data = array();
        $available = $options['more_options']['tokens']['available'];
        if (in_array('vocabulary', $available)) {
          $vocabs = taxonomy_get_vocabularies();
          $data['vocabulary'] = $vocabs[$filters[$label]->options['vid']];
        }
        /* Others? */

        // Replace tokens.
        $options['more_options']['bef_filter_description'] = token_replace(
          $options['more_options']['bef_filter_description'], $data
        );
        $form[$filter_id]['#bef_description'] = $options['more_options']['bef_filter_description'];
      }

      // Handle filter value rewrites.
      if (!empty($options['more_options']['rewrite']['filter_rewrite_values'])) {
        $lines = explode("\n", trim($options['more_options']['rewrite']['filter_rewrite_values']));
        $rewrite = array();
        foreach ($lines as $line) {
          list($search, $replace) = explode('|', $line);
          if (isset($search)) {
            $rewrite[$search] = $replace;
          }
        }

        foreach ($form[$filter_id]['#options'] as $index => $option) {
          $is_object = FALSE;
          if (is_object($option)) {
            // Taxonomy filters use objects instead of text.
            $is_object = TRUE;
            $option = reset($option->option);

            // Hierarchical filters prepend hyphens to indicate depth. We need
            // to remove them for comparison, but keep them after replacement to
            // ensure nested options display correctly.
            $option = ltrim($option, '-');
          }

// LS 8 May 2016 should be $index not $option
          if (isset($rewrite[$index])) {
//          if (isset($rewrite[$option])) {
// LS 8 May 2016 should be $index not $option
          	if ('' == $rewrite[$index]) {
//         		if ('' == $rewrite[$index]) {
              unset($form[$filter_id]['#options'][$index]);
            }
            else {
              if ($is_object) {
                // dsm($form[$filter_id]['#options'][$index]->option, "$filter_id at $index");
                // Taxonomy term filters are stored as objects. Use str_replace
                // to ensure that keep hyphens for hierarchical filters.
                list($tid, $original) = each($form[$filter_id]['#options'][$index]->option);
                $form[$filter_id]['#options'][$index]->option[$tid] = str_replace($option, $rewrite[$option], $original);
              }
              else {
// LS 8 May 2016 should be $index not $option
                      $form[$filter_id]['#options'][$index] = $rewrite[$index];
//              	$form[$filter_id]['#options'][$index] = $rewrite[$option];
              }
            }
          }
        }
      }

Thx.

🐛 Bug report
Status

Closed: won't fix

Version

3.0

Component

Code

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024