Hide block if empty not working

Created on 14 August 2024, 4 months ago

Problem/Motivation

Hide block if empty is not working. I have a block that is showing only a block title and then nothing below that. Based on the configuration of my block (below), I am suspecting the problem might be the fact that I have checked "Hide taxonomy terms if there are no referencing nodes/commerce products". If I uncheck this option, the block will show taxonomy terms with a zero count. So, I suppose the module thinks the block is not empty. However, the block-content element of the block is empty because of the "Hide taxonomy terms if there are no referencing nodes/commerce products" option. So my expectation is that the block should be hidden because block-content is empty.

Steps to reproduce

I have a HTM block configured as follows:

- Display title is checked

Basic Settings:
- Sublevels to display is 0
- Make the block title match the current taxonomy term name is checked (also tried this unchecked)
- Make the menu collapsed by default is checked (also tried this unchecked
- Stay open at the current taxonomy term is unchecked
- Allow parent items to be collapsible and selectable is checked
- Hide block if the output is empty is checked

- No images (so no change to image settings

Advanced Settings:
- Dynamic Base term is checked
- Show count of referencing nodes is selected
- Hide taxonomy terms if there are no referencing nodes/commerce products is checked

πŸ› Bug report
Status

Active

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States aaronpinero

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @aaronpinero
  • πŸ‡ΊπŸ‡ΈUnited States aaronpinero

    I've found the issue:

    On line 620 of HierarchicalTaxonomyMenuBlock.php, the following check is performed:

    if ($this->configuration['hide_block'] && !$vocabulary_tree) {
      return [];
    }

    However, the code then proceeds to build a $vocabulary_tree_array, only then excluding 'empty' terms, as seen on line 642:

    if (!empty($this->configuration['exclude_empty_terms']) && empty($entities)) {
      continue;
    }

    The check to hide the block should be done on $vocabulary_tree_array after it's generated, not before it's generated.

  • πŸ‡ΊπŸ‡ΈUnited States aaronpinero

    I created a simple patch which clears up the issue in my case.

Production build 0.71.5 2024