How to unset or hide a view header / footer when an exposed filter is being applied? I have a header in a view that should be visible only if there are no values in the exposed filters. So, once the user enters any value in any filter and sends the form, this header should not be visible. And the same for a footer in other views.

How to unset or hide a view header / footer when an exposed filter is being applied?
I found this solution that is really very simple:

use Drupal\views\ViewExecutable;
/**
 * Implements hook_views_pre_view().
 */
function MODULE_views_pre_view(ViewExecutable $view, $display_id, array &amp;$args) {
  if ($view-&gt;id() == 'nouvelles' &amp;&amp; $display_id === 'block_1' &amp;&amp; !empty($view-&gt;getExposedInput())) {
    $view-&gt;removeHandler($display_id, 'header', 'view');
    //or 
   // $view-&gt;removeHandler($display_id, 'header', $view-&gt;getHandlers('header')['view']['id']);
  }
}


With the getExposedInput() function you can figures out what the exposed input for this view is, so wee need to check if the returned value is not empty.

The function removeHandler() is the key here, but wee need to know:


  public ViewExecutable::removeHandler($display_id, $type, $id)


$display_id -&gt; is in the function params
$type -&gt; can be header or footer
$id -&gt; view (see the getHandlers() output)


You can found additional info with the getHandlers() function: 

dpm($view-&gt;getHandlers('header'));



Array (
    [view] =&gt; Array
        (
            [id] =&gt; view
            [table] =&gt; views
            [field] =&gt; view
            [relationship] =&gt; none
            [group_type] =&gt; group
            [admin_label] =&gt; 
            [empty] =&gt; 1
            [view_to_insert] =&gt; en_vedette:block_1
            [inherit_arguments] =&gt; 
            [plugin_id] =&gt; view
        )

)