"sort_bef_combine" in page urls is good enough for development, but it's inappropriate for production. The end user will not understand this.
It would be nice to change it to, let's say, just "sort". Is there a way to alter this using hook_form_alter() or some other API functions?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mikeker’s picture

Category: Support request » Feature request

I don't believe there is an easy way to change the query string param via hook_form_alter() or similar because of the way that Views renders exposed form elements. But I haven't tried, so if you do find a way, please report back!

Marking this as a feature request -- it would not be that hard to make the combined sort ID a user-configurable field.

"sort_bef_combine" in page urls is good enough for development, but it's inappropriate for production. The end user will not understand this.

This only appears in the query string as a argument name. As such, it doesn't usually have much user interaction. Or am I missing somewhere else it shows up?

quotesBro’s picture

No, I am only talking about argument name in the query string.

ethanhinson’s picture

This feature would really help me out right now. I have 2 different Views exposed forms with BEF on the same page and I am experiencing collisions caused by non-unique query parameters.

ethanhinson’s picture

After some research, this required a bit of find and replace, but wasn't too bad. This patch will provide a new option under the Advanced fieldset for setting the HTML name of the combined form element.

mikeker’s picture

Status: Active » Needs work

@ethanhinson: Thank you for the patch. In the future, feel free to set the issue to "needs review" if there's a patch or something for the maintainer to review.

  1. +++ b/better_exposed_filters.module
    @@ -12,11 +12,17 @@ function better_exposed_filters_theme($existing, $type, $theme, $path) {
    +      'variables' => array(
    +        'combine_param' => NULL,
    +      ),
    ...
    +      'variables' => array(
    +        'combine_param' => NULL,
    +      ),
    

    If we're going to add this, we should add it for all the theme functions, not just checkboxes.

  2. +++ b/better_exposed_filters.theme
    @@ -193,17 +193,21 @@ function theme_select_as_hidden($vars) {
    -        $hidden = array(
    -          // Custom ID for each hidden field based on the <select> element's
    -          // original ID.
    -          'id' => drupal_html_id($element['#id'] . '-' . $key),
    -          'name' => check_plain($element['#name']) . '[]',
    -          'value' => check_plain($key),
    -        );
    +        // Custom ID for each hidden field based on the <select>'s original ID.
    +        $id = drupal_html_id($element['#id'] . '-' . $key);
    +
    +        // Very similar to theme_hidden()
    +        // (http://api.drupal.org/api/function/theme_hidden/7).
    +        $hidden = '<input type="hidden" '
    +          // Brackets are key -- just like select.
    +          . 'name="' . filter_xss($element['#name']) . '[]" '
    +          . 'id="' . $id . '" '
    +          . 'value="' . check_plain($key) . '" '
    +          . drupal_attributes($element['#attributes']) . ' />';
    ...
    -            '#children' => theme_hidden(array('element' => $hidden)),
    +            '#children' => $hidden,
    
    @@ -493,11 +497,11 @@ function theme_select_as_links($vars) {
    -      $element['#value'][check_plain($index)] = check_plain($item);
    +      $element['#value'][filter_xss($index)] = filter_xss($item);
    ...
    -    $element['#value'] = check_plain($element['#value']);
    +    $element['#value'] = filter_xss($element['#value']);
    
    +++ b/better_exposed_filters_exposed_form_plugin.inc
    @@ -349,10 +357,9 @@ Title Desc|Z -> A</pre> Leave the replacement value blank to remove an option al
    -      $filter_key = $filter->options['is_grouped'] ? 'group_info' : 'expose';
    -      $identifier = '"' . $filter->options[$filter_key]['identifier'] . '"';
    -      if (!empty($filter->options[$filter_key]['label'])) {
    -        $identifier .= t(' (Filter label: "@fl")', array('@fl' => $filter->options[$filter_key]['label']));
    +      $identifier = '"' . $filter->options['expose']['identifier'] . '"';
    +      if (!empty($filter->options['expose']['label'])) {
    +        $identifier .= t(' (Filter label: "@fl")', array('@fl' => $filter->options['expose']['label']));
    
    @@ -720,7 +729,7 @@ Title Desc|Z -> A</pre> Leave the replacement value blank to remove an option al
    -            if (isset($search)) {
    +            if (!empty($search)) {
    
    @@ -890,7 +899,7 @@ Title Desc|Z -> A</pre> Leave the replacement value blank to remove an option al
    -              $form['items_per_page']['#bef_path'] = $this->view->get_path();
    +              $form['items_per_page']['#bef_path'] = isset($this->display->display_options['path']) ? $this->display->display_options['path'] : '';
    
    @@ -920,8 +929,12 @@ Title Desc|Z -> A</pre> Leave the replacement value blank to remove an option al
    -      $filter_key = 'filter-' . ($filters[$label]->options['is_grouped'] ? $filters[$label]->options['group_info']['identifier'] : $label);
    -      $filter_id = $form['#info'][$filter_key]['value'];
    +      if (isset($form['#info']["filter-$label"]['value'])) {
    +        $field_id = $form['#info']["filter-$label"]['value'];
    +      }
    +      else {
    +        $field_id = $form['#info']["filter-{$filters[$label]->options['group_info']['identifier']}"]['value'];
    +      }
    
    @@ -947,12 +960,12 @@ Title Desc|Z -> A</pre> Leave the replacement value blank to remove an option al
    -          if (isset($search)) {
    +          if (!empty($search)) {
    

    These (and lots of others -- I stopped after a few) are unrelated.

I didn't have time to do much more than a drive-by review. If you could clean up the unrelated stuff, it would make it easier to review the rest of your changes.

Thanks.

JeroenT’s picture

Status: Needs work » Needs review
FileSize
8.44 KB

Created a new, smaller patch.

mikeker’s picture

Status: Needs review » Needs work

Looks much better, thanks, @JeroenT! But there still are some problems I came across after some basic testing:

On a new view, settings BEF as the "Exposed form style" and clicking apply results in an error ("Enter a query parameter to use for combined sorts. field is required.").

That may be solved by:

  1. +++ b/better_exposed_filters_exposed_form_plugin.inc
    @@ -108,6 +108,15 @@ class better_exposed_filters_exposed_form_plugin extends views_plugin_exposed_fo
    +        '#title' => t('Enter a query parameter to use for combined sorts.'),
    

    Form field title should not end with a period.

  2. +++ b/better_exposed_filters_exposed_form_plugin.inc
    @@ -108,6 +108,15 @@ class better_exposed_filters_exposed_form_plugin extends views_plugin_exposed_fo
    +        '#default_value' => !empty($existing['sort']['advanced']['combine_param']) ? $existing['sort']['advanced']['combine_param'] : $settings['sort']['advanced']['combine_param'],
    

    $settings is not defined at this point in the code. But this would be a good place to put the currently used default value.

Also, this patch fails the automated tests for BEF (specifically the Link and Rewrite tests) though I haven't had the time to look into those.

JeroenT’s picture

Status: Needs work » Needs review
FileSize
8.41 KB
1.24 KB

Fixed 1 and 2 in #7.

Let's see which tests are still failing.

JeroenT’s picture

This should fix the failing tests.

JeroenT’s picture

mikeker’s picture

Status: Needs review » Fixed

Awesome! Thank you @JeroenT and @ethanhinson! Committed with a slight modification to the #description text so that we don't get a bunch of issues when people put all sorts of crazy characters in the combined sort field... :)

  • mikeker committed 03139f5 on 7.x-3.x
    Issue #2372781 by JeroenT, ethanhinson: Custom BEF combined sort...
  • mikeker committed 4386971 on 7.x-3.x
    Issue #2372781: Specified allowed characters.
    

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

dizee’s picture

Did this patch make it in to the D8 module? I'm not seeing this option anywhere.

SoCalErich’s picture

Any way to get this to work in D9?