Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
There is a hook_block_view_MODULE_DELTA_alter() but there is no hook_block_view_MODULE_DELTA().
Such kind of hook should avoid having multiple if/else or switch/case in the hook_block_view() to test the delta and then call a dedicated function to get the block content.
Comments
Comment #1
cilefen CreditAttribution: cilefen commentedThis would have to be added in Drupal 8 then backported.
Comment #2
vbouchetI think blocks are not using hooks anymore in D8 (or a lot less)
Comment #3
cilefen CreditAttribution: cilefen commentedShould this still be documented in D8? https://api.drupal.org/api/drupal/core!modules!block!block.api.php/funct...
Comment #4
vbouchetMy suggestion is not about the hook_block_view_MODULE_DELTA_alter() which already exists for both D7 and D8 but a suggestion of extending the hook_block_view() which doesn't exist in D8 anymore AFAIK.
Currently in D7:
My suggestion of new hook for D7:
In D8 each block have to extend a class.