Ability to display block_content entities independently, also outside of Blocks

Created on 12 April 2016, over 8 years ago
Updated 11 September 2024, 2 months ago

Problem/Motivation

When I display a custom block using the block layout configuration the block prints using the block.html.twig template. However if I have a custom block view, each row is just the rendered fields, not the whole rendered block. The same problem occurs displaying a rendered block content entity in an ER field or displaying it programmatically like a normal content entity. It causes problems for themers and is inconsistent with similar row formats like "Show: Content" for nodes, and also means that contextual links don't show.

The problem is that block_content entities explicitly have no defined #theme/template because they were expected to always be rendered as a block (core, page_manager, .. doesn't matter, but it has to be a block).

Steps to reproduce:

  1. Create a custom block
  2. Create a view showing custom blocks
  3. For the view format select Show = Custom block

Available workarounds

Proposed resolution

So the answer to this might simply be that this is on purpose, if you want to display something with views or references or ..., then don't use block_content but either a node type or custom entity type. I'm not sure I see an alternative for keeping it working correctly and efficiently (=no double-render caching of the same content, for example) also within a block. However it's a major DrupalWTF moment when you realize this. It's also a while since D8 was released, there's no documentation about this and there's functionality available in core to trigger this bug.

✨ Feature request
Status

Postponed: needs info

Version

11.0 πŸ”₯

Component
Block contentΒ  β†’

Last updated 1 day ago

Created by

πŸ‡¦πŸ‡ΊAustralia rooby

Live updates comments and jobs are added and updated live.
  • DrupalWTF

    Worse Than Failure. Approximates the unpleasant remark made by Drupal developers when they first encounter a particular (mis)feature.

  • VDC

    Related to the Views in Drupal Core initiative.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

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

    Wonder if anyone can confirm if ✨ Add view tab + standard template for block content Needs work solves the problem?

  • πŸ‡¬πŸ‡§United Kingdom AndyF

    Thanks @smustgrave, it'd be great to move this forwards! However there were (at least) a couple of reservations raised with the general idea IIUC:

    block_content entities simply aren't designed to be displayed in another way, if you check the view builder you can also see that it explicitly works around render caching and has that disabled.

    So the answer to this might simply be that this is on purpose, if you want to display something with views or references or ..., then don't use block_content but either a node type or custom entity type. I understand that not everybody will like that but I'm not sure I see an alternative for keeping it working correctly and efficiently (=no double-render caching of the same content, for example) also within a block.

    https://www.drupal.org/project/drupal/issues/2704331#comment-11863202 ✨ Ability to display block_content entities independently, also outside of Blocks Postponed: needs info

    block_content entities are exposed as block plugins and saving reusable blocks triggers a block plugin discovery. The more of them you have the more expensive that becomes.

    https://www.drupal.org/project/drupal/issues/2704331#comment-14604615 ✨ Ability to display block_content entities independently, also outside of Blocks Postponed: needs info

    I don't really grok the double render-caching issue and it's not clear to me why using a custom entity type might be better

    If I build a custom entity type that's similar to block content entities and is for embedded content... I can see at some point being asked to write a plugin to make it accessible to the block system so that we can place these embeddable entities that way too. And then aren't we back in the same situation?

    https://www.drupal.org/project/drupal/issues/2704331#comment-13474270 ✨ Ability to display block_content entities independently, also outside of Blocks Postponed: needs info

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

    Some things to consider.
    The real challenge seems to be determining if block_content entities need to remain coupled with block plugins.

    Based on the information shared:

    1. Caching is tightly coupled between block_content and block plugins
    2. Block plugin discovery is tied to block_content creation
    3. Block plugins are not configurable to conditionally attach entities. There is a unique relationship with block_content and block plugins.

    In response to the caching issue, do we already have an example of double-render caching for the same content in Drupal core? If so then I think the argument is invalid.

    In response to the block plugin challenges, I see this as an opportunity to make the block system more configurable and dynamic for scalability and flexibility. If we make a block plugin that can conditionally attach a block_content entity (or others for that matter) then I see that increases its usefulness and meets the existing expectation. This removes the need for block discovery to be triggered on block_content creation.

    This not only impacts views and references but also impacts using twig_tweak to print a block_content entity in a template. I see all of these as valid use cases and I think the increasing usage of the block_content_template module shows that it should be evaluated.

Production build 0.71.5 2024