Block Content Visibility exposes Drupal core's Condition Plugin System UI directly on the block_content add/edit form. Visibility conditions are stored on the block_content entity and evaluated at render time, so one configuration applies across every placement of that block.

Why

Core stores block visibility on the placement, the block config entity created at /admin/structure/block. That works for a block placed in exactly one region. It stops working when the same reusable block is placed in several regions or themes and the rules should follow the content, when the editors who manage the content have no access to the block layout screen, or when visibility should travel with the content through revisions and translation.

This module adds a third layer, content-level visibility, on a revisionable base field attached to block_content. It is AND-combined with any placement-level conditions, so both layers must pass for the block to render.

Features

  • A Visibility vertical-tabs group on the standard block_content add/edit form, with one tab per Condition plugin available on the site.
  • An explicit "Apply this condition" opt-in per tab, which is what stops a contrib plugin from registering a stored condition merely because its submit handler returned non-default values.
  • Render-time evaluation mirroring core's own BlockAccessControlHandler: per-condition context resolution, a defensive forbid when required context is missing, and full cache-metadata bubbling.
  • A warning on the placement edit form listing the content-level conditions also in play, with a link to edit them, so "why is my block hidden?" has an answer on the screen where it is asked.
  • A settings form to limit which bundles get the UI and to hide Condition plugins from it. Hiding gates the form, never the data: stored conditions for a hidden plugin keep evaluating.
  • No new Condition plugins of its own. The module is plumbing, and its value scales with the plugins already enabled on the site.

Known limitation: Layout Builder

Conditions cannot be set on a Layout Builder inline block. The Visibility UI does not appear in the inline-block dialog, for two reasons that both have to be solved: Layout Builder's form object is not an entity form, which the module's form alter requires, and the form it would attach to is a sub-element, where the entity builder that persists the values never runs.

The evaluation half is in place, so a condition already stored on a block_content revision is honoured for an inline_block plugin. Only the editing half is missing. It is tracked as #3594776. Until it lands, gate Layout Builder blocks with core's placement-level visibility, or make the block reusable and set the condition on the content.

Requirements

  • Drupal 10.3 or newer. Earlier 10.x releases are not supported.
  • PHP 8.2.
  • Block Form Alter 2.x, which provides the form alter hook the module attaches to.

Usage

Open any block content add or edit form, scroll to the Visibility group, open the tab for the condition you want, tick Apply this condition, configure it and save. The condition then applies to every existing and future placement of that block. The permission is administer block content visibility; without it the UI is hidden and stored conditions keep evaluating, so revoking it never silently disables a rule.

Supporting organizations: 

Project information

Releases