- πΊπΈUnited States smustgrave
@rohit.rawat619 that patch not sure matches when was in the D7 ticket. How come?
@andypost what needs to be ported?
- Status changed to Postponed: needs info
about 1 year ago 4:06pm 22 May 2024 - Status changed to Closed: outdated
12 months ago 7:47pm 9 June 2024 - π¨π¦Canada joseph.olstad
@smustgrave, please reopen this, Andypost is correct, this patch needs to be ported. I'm using Drupal 10.4 with a checkbox exposed bef , the issues reported by Andy Post relating to the patch that needs porting is still unresolved for 8.x-3.x or whatever it's called now.
- πΊπΈUnited States smustgrave
Will 8.x-.3x is unsupported and 6.0.x is essentially unsupported just not marking it
- πΊπΈUnited States smustgrave
May be a dup of https://www.drupal.org/project/better_exposed_filters/issues/2921024 π Not possible to unselect the checkbox Active
- π¨π¦Canada joseph.olstad
Ok I have figured out a solution for this, here is the crux of it:
mymodule.views.inc
use Drupal\Core\StringTranslation\TranslatableMarkup; /** * Implements hook_views_data_alter(). */ function mymodule_views_data_alter(array &$data) { $data['paragraphs_item_field_data']['include_session_paragraph'] = [ 'title' => new TranslatableMarkup('Show event sessions'), 'help' => new TranslatableMarkup('Show event "session" paragraphs toggle filter. When off/false, only calendar_entry paragraphs are included in the results.'), 'filter' => [ 'id' => 'include_session_paragraph', 'group' => 'MyModule', ], ]; }
src/Plugin/views/filter/IncludeSessionParagraph.php
namespace Drupal\mymodule\Plugin\views\filter; use Drupal\views\Plugin\views\filter\BooleanOperator; use Drupal\Core\Form\FormStateInterface; /** * Controls paragraph filtering by presence of field_title (i.e. calendar_entry only). * * @ingroup views_filter_handlers * * @ViewsFilter("include_session_paragraph") */ class IncludeSessionParagraph extends BooleanOperator { /** * Workaround for BEF checkbox filters. */ public function acceptExposedInput($input) { if (!parent::acceptExposedInput($input)) { return FALSE; } // If the filter value is not present in the input, reject. // This is the critical fix for BEF + Single On/Off checkbox. $identifier = $this->options['expose']['identifier']; if (!array_key_exists($identifier, $input)) { return FALSE; } return TRUE; } /** * {@inheritdoc} */ protected function defineOptions() { $options = parent::defineOptions(); return $options; } /** * {@inheritdoc} */ public function buildOptionsForm(&$form, FormStateInterface $form_state) { parent::buildOptionsForm($form, $form_state); $form['value']['#title'] = $this->t('Show event sessions'); } /** * {@inheritdoc} */ public function query() { $identifier = $this->options['expose']['identifier']; $input = $this->view->getExposedInput(); $include_sessions = isset($input[$identifier]) && $input[$identifier] === '1'; if (!$include_sessions) { $alias = $this->query->ensureTable('paragraph__field_title', 'paragraphs_item_field_data'); $this->query->addWhereExpression(1, "$alias.field_title_value IS NOT NULL"); } } }
So this filter is added and in bef configured as a single checkbox in the advanced options of bef
The crux was adding the acceptExposedInput method which sets up the expose identifier and adjusting the query method to capture the input
(from the query method) like this:
$identifier = $this->options['expose']['identifier']; $input = $this->view->getExposedInput(); $include_sessions = isset($input[$identifier]) && $input[$identifier] === '1';
So, I got it working without a patch.
Otherwise the value is always true no matter what was selected so could not use $this->value , instead use the approach mentioned above until this is fixed.
- πΊπΈUnited States smustgrave
Fix will ultimately be over in π Not possible to unselect the checkbox Active