Score:1

How to override facets checkbox theme and style checkboxes checked state?

tr flag

I'm having trouble to style Drupal 9 facets checkbox in checked state. I have tried to override the theme by theme_preprocess_checkboxes with no effect.

here is my code :

 function mytheme_preprocess_checkboxes($variables) {

  $element = $variables['element'];
  $element['#attributes']['type'] = 'checkbox';
  element_set_attributes($element, array('id', 'name', '#return_value' => 'value'));

  // Unchecked checkbox has #value of integer 0.
  if (!empty($element['#checked'])) {
      $element['#attributes']['checked'] = 'checked';
  }
  _form_set_class($element, array('form-checkbox'));

  return '<input' . drupal_attributes($element['#attributes']) . ' /><span></span>';
}

I guess i'm not getting facets checkboxes with it. Any suggestions how do i style facets and override their templates.

I'm using bootstrap 3 subtheme on drupal 9

Vitaliy K avatar
tr flag
Unfortunately preprocess_checkboxes hook is depricated and will be no longer available from Drupal 10 version... so looking for the solutions. probably i need to rewrite twig temeplate but still can't find it even in facets module templates folder... :(
Vitaliy K avatar
tr flag
getting more closer to it : public static function Checkbox::preRenderCheckbox for non facets checkboxes in checked stade adds to element css class. butr still canot track the facets chekbox renedering
Score:1
cn flag

The checkboxes are created in JS, not PHP, so you won't be able to manipulate them from the backend (see Drupal.facets.makeCheckbox in facets/js/checkbox-widget.js for the code).

It does mean you can just use some simple JS yourself, though; for example assuming you need to append an empty span you'd, probably just need to add something like this to a custom behavior:

$('.facets-checkbox').after($('<span />'))

(that's just a minimal example, you should use once or a similar mechanism to make sure it isn't executed multiple times for the same element).

Vitaliy K avatar
tr flag
Thanks Clive will try this bit
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.