Problem/Motivation

Using Views UI, you can reorder fields in the Filter Criteria, including fields exposed to visitors. The BEF settings give you the option to move exposed fields into a "secondary" fieldset. The problem is that when the view is rendered, fields in the secondary fieldset are not shown in the order set in the UI.

Steps to reproduce

Add more than one exposed field under Filter Criteria. Change Exposed Form Style to BEF. Edit BEF settings. Click "Enable secondary exposed form options", then scroll down and expand "More options" for each exposed form field, and check "This is a secondary option". Save the view.

Visit the page where the form is shown, and make a note of the order of the secondary exposed fieldset.

Return to the view. Change the order of the fields. Save the view and view the page with the form. Note that the order of the fields in the secondary exposed fieldset has not changed.

Under the hood

Issue #2692083: Secondary filter position broken when using custom filter identifier points to the code where the field weight is set (#bef_position), i.e. $filters[$label]->position. However, That property never seems to exist in my testing.

The BEF module is just getting the $filters in a standard way using $form_state['view']->display_handler->handlers['filter']; on line 1155 of better_exposed_filters_exposed_form_plugin.inc.

From what I understand looking through the Views module code, the position property is only set during $view->_pre_query() which is called inside of $view->build().

That position-ordering code is happening inside of exposed_form_alter() which probably runs before $view->_pre_query(). Hence why position doesn't exist yet. (Or maybe it does in other scenarios, but my testing never showed it.)

Proposed resolution

The attached patch gets the order of the fields in the $filters array to get the relative position for each field. It then uses that field order when $filters[$label]->position doesn't exist.

Comments

hargobind created an issue. See original summary.

hargobind’s picture

Status: Active » Needs review
StatusFileSize
new1.97 KB
hargobind’s picture

Issue summary: View changes
hargobind’s picture

Issue summary: View changes
hargobind’s picture

StatusFileSize
new1.58 KB

Attaching a patch which fixes a logic bug.

neslee canil pinto’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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