From 8f0ea21009f1e0de256605f9402ab595c47b9ce9 Mon Sep 17 00:00:00 2001
From: nickvh <nickvh@122682.no-reply.drupal.org>
Date: Tue, 11 Jun 2019 17:35:26 +0300
Subject: [PATCH] Issue #2984465 by Nick_vh, akalam, borisson_, seanB, nedjo,
 ChristianAdamski, estoyausente: Hide facets when it is configured to hide the
 block without losing support for bigpipe and ajax facets

---
 facets.module                            | 6 ++++++
 src/FacetManager/DefaultFacetManager.php | 2 +-
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/facets.module b/facets.module
index 5308dcf7..07b5f9d5 100644
--- a/facets.module
+++ b/facets.module
@@ -149,6 +149,12 @@ function facets_entity_presave(EntityInterface $entity) {
  */
 function facets_preprocess_block(&$variables) {
   if ($variables['configuration']['provider'] == 'facets') {
+    // Hide the block if it's empty.
+    if (!empty($variables['elements']['content'][0]['#attributes']['class']) && in_array('facet-hidden', $variables['elements']['content'][0]['#attributes']['class'])) {
+      // Add the Drupal class for hiding this for everyone, including screen
+      // readers. See hidden.module.css in the core system module.
+      $variables['attributes']['class'][] = 'hidden';
+    }
     if (!empty($variables['derivative_plugin_id'])) {
       $facet = Facet::load($variables['derivative_plugin_id']);
       $variables['attributes']['class'][] = 'block-facet--' . Html::cleanCssIdentifier($facet->getWidget()['type']);
diff --git a/src/FacetManager/DefaultFacetManager.php b/src/FacetManager/DefaultFacetManager.php
index 162b03d4..70538823 100644
--- a/src/FacetManager/DefaultFacetManager.php
+++ b/src/FacetManager/DefaultFacetManager.php
@@ -350,7 +350,7 @@ class DefaultFacetManager {
             '#type' => 'container',
             '#attributes' => [
               'data-drupal-facet-id' => $facet->id(),
-              'class' => ['facet-empty'],
+              'class' => ['facet-empty', 'facet-hidden'],
             ],
           ],
         ];
-- 
GitLab