Repro steps:

  1. A view with a block display.
  2. The block has a taxonomy filter that is exposed as a dropdown
  3. The block display is set to use AJAX
  4. Define template suggestions for the select and label:
    function HOOK_theme_suggestions_form_element_label_alter(&$suggestions, &$vars) {
      $element = $vars['element'];
    
      $suggestions[] = $vars['theme_hook_original'] . '__' . str_replace('-', '_', $element['#id']);
    }
    
    function HOOK_theme_suggestions_select_alter(&$suggestions, &$vars) {
      $element = $vars['element'];
    
      $suggestions[] = $vars['theme_hook_original'] . '__' . str_replace('-', '_', $element['#id']);
    }
    
  5. Create new override templates using the new suggestions above in your theme
  6. The twig templates display correctly on first load
  7. Apply the exposed filter, and the markup surrounding the exposed filter reverts back to core templates

Expected Behavior

I would expect the override templates for the exposed filter to continue to work after applying the filter.

What happens instead

The template overrides are ignored and the core templates are used instead. I can see the suggestions still in the Twig debug statements, but they aren't used after the filter has been applied.

Comments

chrisbudy created an issue. See original summary.

josh.fabean’s picture

Can confirm I also experience this issue. I am currently investigating solutions.

chrisbudy’s picture

Status: Active » Closed (works as designed)

Finally had a chance to revisit this and look into it further. I was building suggestions based off of a $vars['element']['#id'] for hook_theme_suggesstions_input_alter() and hook_theme_form_element_alter(), but these values don't stay consistent. Upon submitting an AJAX form submission these values tack on some unique id to the end of the id name, which is what caused my templates to no longer be valid. So I had a template like input--edit-my-field-id.html.twig but after the form submit the id changed and was therefore looking for a template like input--edit-my-field-id-55FGSA1.html.twig.

So I switched over to making my theme suggestions based off of the element's #name property instead, as it is very similar, and doesn't change. This resolved my issue.