Decide if and how block plugins should alter the BlockViewBuilder generated render array

Created on 7 April 2015, about 10 years ago
Updated 8 May 2025, 2 days ago

Problem/Motivation

  • BlockViewBuilder::viewMultiple() (BVB) generates a render array for a block that gets some information from the block configuration entity, some from the block plugin, and some from the internal logic of BVB.
  • BVB invokes an alter hook to then allow modules to alter that result.
  • After #2459819: Remove CacheableInterface (and no longer let block plugins implement it) β†’ , we have a use case for block plugins themselves wanting to alter the BVB generated array. For example, the SystemPoweredByBlock is cheaper to render than the cost of a cache_get(), so it may want to unset #cache['keys'] in order to optimize away the caching of itself on its own. Note that it does not and should not do this by implementing getCacheMaxAge() of 0, because the contents are cacheable, and it's necessary for higher-level caches, such as the page cache to know that. So unsetting the cache keys isn't about informing the system that the contents are uncacheable, but about optimizing away a decision to cache it at that particular level.
  • There might be other use cases for a block plugin to alter the BVB array? Perhaps changing #theme?
  • The above use cases can be implemented via the alter hook, but that then places the implementation in a separate place (e.g., in a .module file) from the plugin.

Proposed resolution

?

Remaining tasks

Discuss.

User interface changes

API changes

πŸ“Œ Task
Status

Postponed: needs info

Version

11.0 πŸ”₯

Component

block.module

Created by

πŸ‡ΊπŸ‡ΈUnited States effulgentsia

Live updates comments and jobs are added and updated live.
  • stale-issue-cleanup

    To track issues in the developing policy for closing stale issues, [Policy, no patch] closing older issues

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

    Thank you for creating this issue to improve Drupal.

    We are working to decide if this task is still relevant to a currently supported version of Drupal. There hasn't been any discussion here for over 8 years which suggests that this has either been implemented or is no longer relevant. Your thoughts on this will allow a decision to be made.

    Since we need more information to move forward with this issue, the status is now Postponed (maintainer needs more info). If we don't receive additional information to help with the issue, it may be closed after three months.

    Thanks!

Production build 0.71.5 2024