Score:0

How to override views-exposed-form in a module?

in flag

I'm trying to override views-exposed-form. It works fine in a theme, but it's strange in a module. Eventually, it does find the template, but the form is available as {{ element }} and is missing the actual form tag - it's just the children.

<form>{{ element }}</form> sort of works.

In my module, I have

function MYMODULE_theme_suggestions_form(array $variables) {
  if ($variables['element']['#form_id'] == 'views_exposed_form') {
    return ['form__my_views_exposed_form'];
  }
  return [];
}

function MYMODULE_theme($existing, $type, $theme, $path) {
  
  $incfile = '../../../../../'.\Drupal::service('module_handler')
      ->getModule('views')
      ->getPath().'/views.theme.inc';

  return [
    'form__my_views_exposed_form' => [
      'template' => 'my-views-exposed-form',
      'path' => $path . '/theme/templates',
      'file' => $incfile,
      'render element' => 'form',
      'base hook' => 'form'
    ],
  ];
}

The file is taken from the views module .. the render element and base hook don't actually seem to matter much.

What am I missing ?

I sit in a Tesla and translated this thread with Ai:

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.