I'm using Term Condition together with Block Visibility Groups.

The latter works perfectly but, when Term Condition is added I find that blocks, even though they have no visibility settings defined, are not being rendered on pages produced by Views. To be clear, those blocks are global, and appear fine on all content-type pages, just not pages created by Views.

The issue doesn't affect blocks created before Term Condition was installed unless that block is subsequently saved.

Comments

mr_phillip created an issue. See original summary.

j.b’s picture

Not only for view pages but if i resave any blocks.
they are not displayed

j.b’s picture

mr_phillip did you find a solution for this bug ?

dieuwe’s picture

Priority: Major » Critical

When saving any block, this gets added to the YAML:

visibility:
  term:
    id: term
    negate: false
    tid: null
    context_mapping:
      node: '@node.node_route_context:node'

I believe this "empty" snippet is what causes the blocks to be hidden from any non-node pages.

Working on a patch.

dieuwe’s picture

Title: Causing blocks to be hidden on Views pages for no clear reason » Causing blocks to be hidden on Views, User, and all non-node pages
Status: Active » Needs review
StatusFileSize
new891 bytes

Term condition is requiring all blocks to have a node context from a route. When a page does not have a node, the block is hidden because the condition will not be evaluated. So even if you left the term condition empty (null), then the block will still be hidden.

In the attached patch, we make the node context no longer required. This will give you an extra option field to select the context on the block configuration form, but "node from URL" seems to be selected by default so the overall behaviour of the module is not affected.

This change will of course cause fatal errors on non-node pages, as the function that evaluates the condition assumes a node will be present, so the second half of the patch will ensure that FALSE is returned if a node is not present. Again, this ensures normal/expected behaviour (non-node pages can obviously not have terms assigned to them and so will always return FALSE.)

Hopefully this is a satisfactory approach, but if not, then I hope it points you in the right direction.

dieuwe’s picture

I should add that all you should need to do after applying the patch is to flush the cache and all blocks should behave as expected without needing to be edited/resaved.

dieuwe’s picture

Sorry, patch in #5 is malformed, this is the correct one.

cayenne’s picture

Issue summary: View changes

Having a little difficulty with the patch.

Apparently, need the option of p1, rather than p0.

Once installed, it did the trick.

danielveza’s picture

Status: Needs review » Reviewed & tested by the community

Ran this on my D8 site which had this exact problem and it solved the issue.

camhoward’s picture

The patch in #7 also solved the issue for me. Thanks!

tmountjr’s picture

Patch in #7 worked for me.

8thom’s picture

Confirmed patch in #7 is working nicely.

ckaotik’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new647 bytes

While the proposed patch fixes the symptoms, it does not resolve the actual cause of the issue. I've attached a patch that should fix the detection of an "empty" term condition, please try that one instead.

When you save the condition, e.g. as part of a block's visibility, the responsible module (for block visibility: Core's block module) will compare the saved configuration against the default configuration. If there are differences, the condition is considered as "used" and will be evaluated.
The patch works by telling the handling module that the configuration will have the tid key, but if it's empty, it's the default.

The problem occurs because the condition is considered "not empty", even though it should be. Then it requires a node with the "" term, which fails on many pages, thus permanently breaking any block being saved with the broken term condition. If you were to uninstall the module term_condition, all those blocks would be deleted, as they incorreclty have a dependency on the module.

criscom’s picture

The patch in #13 did not work for existing blocks. After applying patch in #7 it worked.

giorgosk’s picture

Status: Needs review » Reviewed & tested by the community

#13 did not work for existing blocks even after resaving their configuration manually
#7 worked after clearing the cache
I believe #7 should be reviewed and tested

jastraat’s picture

+1 for patch #7

danielveza’s picture

Having reviewed the issue some more and doing some testing - I can see the issue is solved by patch #7 and that patch is needed, but patch #13 is also correct and needs to be fixed as well.

As Ckaotik says, without his patch any new blocks created are saved with a term of "". His issue fixes that, so only blocks with term conditions are effected by this module rather than all of them.

I've combined these patches into two and it's passed my testing. If someone could test this patch and verify that would be great. Otherwise I'll commit in a day or two.

  • DanielVeza committed 2215bf4 on 8.x-1.x
    Issue #2797205 by dieuwe, DanielVeza, ckaotik, mr_phillip, Cayenne,...
danielveza’s picture

Status: Reviewed & tested by the community » Fixed

Thanks all!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.