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 are self-declared implementations of hook_block_alter in Drupal core, but there is no documentation of the hook itself. Patch to follow.
Comment | File | Size | Author |
---|---|---|---|
#24 | hook_block_alter_doc-2717541-24.patch | 849 bytes | sulfikar_s |
#23 | interdiff_14-23.txt | 575 bytes | manish-31 |
#23 | 2717541-23.patch | 575 bytes | manish-31 |
#20 | 2717541-after_patch-14.png | 85.67 KB | Abhijith S |
#18 | Screen Shot 2020-09-01 at 12.14.19 PM.png | 372.25 KB | tanubansal |
Comments
Comment #2
jhodgdonWell, that's very interesting. I see two implementations in core -- one in a test, and one in statistics.module. But I don't see where this hook is invoked. Any ideas?
Comment #3
jhodgdonComment #4
progga CreditAttribution: progga as a volunteer commentedAccording to Berdir's StackOverflow answer, it is called in \Drupal\Core\Block\BlockManager
Comment #7
andypostWhat is a proper place to put this hooks?
Example of usage
Comment #8
andypostI think for blocks it makes sense to have separate *.api.php like menu has
core/lib/Drupal/Core/Menu/menu.api.php
Comment #12
msankhala CreditAttribution: msankhala at Srijan | A Material+ Company commentedHere is the patch.
Comment #13
andypostDefinitions should be typed, I bet it kinda
\Drupal\Component\Plugin\Definition\PluginDefinitionInterface[]|array[]
as\Drupal\Core\Plugin\FilteredPluginManagerInterface::getFilteredDefinitions()
returnsComment #14
msankhala CreditAttribution: msankhala at Srijan | A Material+ Company commented@ashrafabed Now @param line length is going more than 80 characters. Is it allowed to go more than 80 characters if we specify FQN of the types of param?
Comment #18
tanubansal CreditAttribution: tanubansal at Salsa Digital commentedTested #14, hook_block_alter code has been added
Comment #20
Abhijith S CreditAttribution: Abhijith S as a volunteer and at Zyxware Technologies commentedApplied patch #14 and it works . The hook_block_alter is correctly documented in the patch
Comment #21
Abhijith S CreditAttribution: Abhijith S as a volunteer and at Zyxware Technologies commentedComment #22
alexpottWe know that blocks are not going to be
\Drupal\Component\Plugin\Definition\PluginDefinitionInterface[]
so onlyarray[]
is needed here.Comment #23
manish-31 CreditAttribution: manish-31 at OpenSense Labs for DrupalFit commented@alexpott removed PluginDefinitionInterface[], needs review.
Comment #24
sulfikar_s CreditAttribution: sulfikar_s at Zyxware Technologies commentedHello,
As the patch in #23 failed to apply and found to be not a proper patch. I've created a new patch addressing the comment #22.
Please review.
Comment #25
Vishalghyv CreditAttribution: Vishalghyv at Google Summer of Code commentedPatch looks good to me.
Comment #28
catchCommitted/pushed to 9.2.x and cherry-picked to 9.1.x, thanks!