To allow for BEF to display the exposed sort options as Links, Toggle Links or Radio buttons you have to select the "Expose sort order" option. But when you just want a link to sort only one way, for example "new item on top" you don't need the sort order exposed.

The following patch fixes this by allowing to use the "Display exposed sort options as" regardless of the exposed sort order.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dazz’s picture

jfrederick’s picture

Patch #1 works, but introduces PHP warnings such as, "Notice: Undefined index: #name in theme_select_as_links() (line 460 of /var/www/career/sites/all/modules/contrib/better_exposed_filters/better_exposed_filters.theme)."

This is because the module previously assumed that if you were displaying your exposed sort options as links, then both 'sort by' and 'sort order' form elements must have been present. The module then manipulates those specific form elements. However, since this patch makes it possible to theme the form elements as links without including 'sort order', we have to ensure the individual form elements exist before manipulating them.

This patch also omits from #1 some undesirable spacing issues and changes that appear unrelated to this issue.

brunorios1’s picture

Status: Active » Reviewed & tested by the community

#2 worked for me, but shows warning in panels:

Notice: Undefined index: path in better_exposed_filters_exposed_form_plugin->exposed_form_alter() (line 817 of /var/www/myproect/docroot/sites/all/modules/contrib/better_exposed_filters/better_exposed_filters_exposed_form_plugin.inc).

brunorios1’s picture

Status: Reviewed & tested by the community » Needs work
interdruper’s picture

#2 works fine for me. The issue reported in #3 may be unrelated to this patch, it seems so watching the code:

812 // Exposed form displayed as blocks can appear on pages other than the
813 // view results appear on. This can cause problems with
814 // select_as_links options as they will use the wrong path. We provide
815 // a hint for theme functions to correct this.
816 if (!empty($this->display->display_options['exposed_block'])) {
817    $form[$element_name]['#bef_path'] = $this->display->display_options['path'];
818 }

@brunorios1, could you confirm that the notice in your particular view only appears after applying the patch ?

phamkhaclam90@gmail.com’s picture

This is the result when I apply patch in #2:

Hunk #1 succeeded at 646 (offset 15 lines).
Hunk #2 succeeded at 678 (offset 15 lines).
Hunk #3 FAILED at 804.

The code must be:
$form['sort_bef_combine']['#bef_path'] = isset($this->display->display_options['path']) ? $this->display->display_options['path'] : '';
instead of:

$form['sort_by']['#bef_path'] = $this->display->display_options['path'];
$form['sort_order']['#bef_path'] = $this->display->display_options['path'];

Please check this, I'm using version 7.x-3.x-dev, date 2014-Sep-01

quotesBro’s picture

re-roll against latest dev (2014-Nov-03)

quotesBro’s picture

patch works well for me.

szeidler’s picture

Works also fine for dev (2014-Nov-13). Should definitely be committed.

mikeker’s picture

Status: Needs review » Postponed (maintainer needs more info)

Apologies for taking so long to get to this issue.

Can't the original request be done by rewriting the output of the sort options you don't want to NULL? Eg: you have "post date" and "title" set as exposed sorts. You can set the rewrite text to be:

Post date Asc|
Post date Desc|Newest first
Title Asc|Alphabetical
Title Desc|

To only have the options "Newest first" and "Alphabetical" show.

Or am I missing something? Thanks.

jfrederick’s picture

Status: Postponed (maintainer needs more info) » Needs review

Since the module exposes the option to display the sort options as links in the admin UI, it seems to me that no code or Views re-rewriting should be necessary to perform that advertised function. I think exposed sorts without exposed sort direction is a common-enough use case to warrant making it easy to accomplish. I am thinking of 'Latest' Views, 'Most Popular' views, etc, where the reverse sort seems pretty uninteresting to a site user.

Alternatively, there could be help text explaining that one must also expose the sort direction for the links to work, and help text echoing the solution in #10. That sounds unintuitive to me, as the patch builds the feature into the UI rather than having to add and then rely on people reading a how-to.

@mikeker, do you see downsides to incorporating the patch? Thanks.

mikeker’s picture

Status: Needs review » Needs work

@jfrederick: Thanks for the explanation -- I think the use-case you describe is valid and you make a good point about "making it easy to accomplish," which is what this module is all about. OK, I'm open to adding this -- for the record, my main objection was adding more complexity to the already complex UI code.

However, I get

Notice: Undefined index: #options in form_process_radios() (line 3017 of <snip>\includes\form.inc).

when I use radio buttons for the exposed sort settings.

lachezar.valchev’s picture

Hi,

Here is re-rolled the patch from #7 so that it works with the latest stable version released yesterday.

Regards,
Lachezar

lachezar.valchev’s picture

Status: Needs work » Needs review

Hi,

Changed the issue status to Needs Review in order to check the re-rolled patch.

Regards,
Lachezar

jenlampton’s picture

I'm not sure this patch is still necessary, as I am able to expose the sort options as links without also selecting 'Expose sort order'. If that's not the problem this patch is aiming to correct, would someone please update the issue summary?

szeidler’s picture

I'm using BEF 7.x-3.2 and with deactivating the Expose sort order checkbox everything work like expected, too.4 Can someone, who has reported the issue, can verify that?

shahidaali’s picture

Notice: Undefined index: #options in form_process_radios() (line 3017 of \includes\form.inc).

This issue is generated because #options missing in sort_order element. Added following code fixed the issue.

$form['sort_order']['#type'] = 'radios';
if(empty($form['sort_order']['#options'])) {
  $form['sort_order']['#options'] = array();
}

On line 855 in better_exposed_filters_exposed_form_plugin.inc after applying patch from #13

svetoslav.dragoev’s picture

Re-roll of #13 against the release from 25 Oct 2017 - dev. Also compatible with version 7.x-3.5.

svetoslav.dragoev’s picture

Fix in patch #18, removed wrong diff paths, set them to root.

Neslee Canil Pinto’s picture

Status: Needs review » Closed (won't fix)

Hi, there will be no more future development for 7.x branch. If you see this issue in 8.x, feel free to file an issue. Closing this as Closed(wont fix).