I have taxonomy term names as an exposed filter and under Display "tid" exposed filter as I selected links however any is being displayed. I can understand the use case for any but this is completely pointless when filtering by links.

I tried to use but I guess that was being a little cheeky. Is their anyway to hide the -any-.

CommentFileSizeAuthor
#5 Events.png76.9 KBcorbacho
#2 bef-any.png22.45 KBinterdruper
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Road Kill created an issue. See original summary.

interdruper’s picture

Status: Active » Closed (works as designed)
FileSize
22.45 KB

You have just to rewrite the filter options, leaving blank the rewrite:

Hide-any

corbacho’s picture

I have the same problem. I tried all these solutions, one by one, and still it shows up.

-Any-|
- Any -|
- Any -| (with an extra space after |)

corbacho’s picture

Status: Closed (works as designed) » Active

I'm using 8.x-3.0-alpha1, I wouldn't like to hijack this issue, though and re-assign from 7.x

corbacho’s picture

FileSize
76.9 KB

The problem is that "- Any -" doesn't match the "All" , in the logic of rewriting , file BetterExposedFilters.php
Screenshot of array structure

 foreach ($options as $index => $option) {
      if (isset($rewrites[$option])) {
        if ('' == $rewrites[$option]) {
          unset($return[$index]);
        }
        else {
          $return[$index] = $rewrites[$option];
        }
      }
    }

I'm using this form_alter in the meanwhile (based on https://www.drupal.org/node/1537074 (comment 3))

/**
 * Implements hook_form_alter().
 */
function YOURMODULE_form_alter(&$form, FormStateInterface $form_state, $form_id) {
  // Rewrite first item for exposed filters
  if ($form_id == 'views_exposed_form' && $form['#id'] === 'views-exposed-form-events-block-1') {
    foreach ($form['#info'] as $filtername => $filterdefs) {
      $fieldname = substr ($filtername, strlen('filter-'));
      if($form[$fieldname]['#type'] == 'radios') {
        // Unset the - Any - option
        unset($form[$fieldname]['#options']['All']);
      }
    }
  }
}
mikeker’s picture

Can someone try the patch in #2756693: Cannot rewrite filter options with non-alphanumeric characters and let me know if it solves your problem?

(Also, you can make the filter required to remove the "any" option.)

mikeker’s picture

Status: Active » Postponed (maintainer needs more info)

re: @corbacho in #5:

I think you're using an older version of BEF. That should have been fixed in this commit from Aug 2016. However, there is still an outstanding issue: #2666540: Rewrites do not work for taxonomy filters (D8-only).

I should also point out that removing the any/all option may give you the dreaded "illegal choice" error. It might be good to special case that situation in BEF.

corbacho’s picture

Thanks Mike. Problem solved after updating the module to alpha-2. The only issue is an annoying PHP warning but I fixed it with patch #4 from #2822916: Set selected variable before rewriting filter option 'Undefined variable: selected'

mikeker’s picture

Status: Postponed (maintainer needs more info) » Closed (outdated)

Issue queue cleanup. Based on #8 it sounds like this has been resolved.