0

Over at this previous question I figured out how to give a view a list of options that look like this:

Sort by

  • Date - Newest
  • Date - Oldest
  • Price - Highest
  • Price - Lowest

Suppose there was a particular sort order combination of sort option and sort direction that didn't make any sense. For example, imagine an "Editor's Choice" sort, where staff apply a rating to products to give the best products a boost.

This makes sense:

Sort by

  • Editor's choice
  • Date - Newest
  • Date - Oldest
  • Price - Highest
  • Price - Lowest

This is just a bit strange:

Sort by

  • Editor's choice - most favoured
  • Editor's choice - not favoured
  • Date - Newest
  • Date - Oldest
  • Price - Highest
  • Price - Lowest

...not least because 50%+ of products will be equally at the bottom of the "not favoured" list. This sort might also give the misleading impression that the product at the top of the "not favoured" list has something wrong with it, when actually it's equally not-singled-out-for-praise with 50% or more of the shop.

What I'm currently doing, is the brute force approach - using CSS to set the option based on 'Editor's choice Ascending' to display: none;. I don't like this, because the wrappers mean I have to use first/nth child selectors which could mean the option gets hidden in future after a seemingly inconsequential update or views config change.

Is there a more stable way to properly remove this option from the form?

1 Answer 1

1

I can't find a way to do it through Views or Better Exposed Filters settings, but I have found a way through hook_form_alter() in the theme template.php file:

Something like this, specific array keys are based on using the BEF combine option and may vary:

function YOURTHEME_form_alter(&$form, $form_state, $form_id){
  switch ($form_id)  
  case 'views_exposed_form':
    if($form['#id'] == 'views-exposed-form-VIEWID-DISPLAYID'){
      if( isset($form['sort_bef_combine']['#options']['field_FIELDNAME ASC']) ){
        $form['sort_bef_combine']['#hidden_options']['field_FIELDNAME ASC'] = $form['sort_bef_combine']['#options']['field_FIELDNAME ASC'];
        unset($form['sort_bef_combine']['#options']['field_FIELDNAME ASC']);
      }
    } 
  break;
  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.