0

So, I have a Custom Block type, let's call it Sidebar Links Block. In an Article, we have a Sidebar paragraph type that allows quite a few different entities, one of which is the Article Sidebar Links paragraph type.

The Article Sidebar Links ¶ type (which is one of the fields of our Article type) contains a single entity reference to a Custom Block type, the aforementioned Sidebar Links Block.

If I change, say, the Title of the Sidebar Links Block, that change is not reflected in the paragraph type's output. In other words, when viewing an Article where we changed the contents of one of the referenced Custom Block types, it still shows the old contents, before the change.

Even clearing the Drupal caches in the usual way, does nothing. What I have to do, instead, is:

  • Edit the Article
  • Move any ¶ type up or down, then move it back (this triggers the form's JS that detects changes, allowing you to re-save with essentially no real changes)
  • Re-save the Article

This finally causes the Title to update in the Article Sidebar Links ¶ type where the Sidebar Links Block is referenced and displayed.

Is there any way around this? Currently, whenever we update a Custom Block, we have to apply this manual fix to every single Article where it's referenced. I have a hunch that it has something to do with cache tags, but I don't know enough to be able to investigate. Does anybody have any ideas as to how this can be fixed?

  • Obviously the block content cache tag is not merged into the paragraph. So it isn't enough to resave the node, you need that trick to resave the paragraph, too. I don't know how you referenced the block content, but try the Block Field module and this patch drupal.org/project/block_field/issues/2999660 – 4k4 Mar 29 at 16:44
  • The custom block is referenced via paragraph type, which contains an entity reference to custom blocks. In other words, Article has a field "Sidebar Contents", which can point to any number of paragraph types, including "Article Sidebar Links". When you add that para. type, you can select which Custom Block it will reference (via autocomplete). These blocks can be shared across multiple Articles, so changing the contents of the custom block should update all Articles containing the block (through paragraph type). – TerranRich Mar 29 at 17:09
  • 1
    Yes, it should, but block content is not a normal entity, because it has no template of its own and this breaks the bubbling of cache tags. Try the suggested module to reference the block content because it has a solution for the problem. Or you need to implement similar code in a paragraph preprocess hook to merge the cache tags, see drupal.stackexchange.com/questions/225548/… – 4k4 Mar 29 at 17:18
0

So the way that I ended up fixing this, was to use Twig Tweak to output the content block directly, like so:

{{ drupal_entity('block_content', content_block_id) }}

This ends up bypassing Drupal cache. Barring a better fix, this is the one I'm going with.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.