- 🇬🇧United Kingdom AndyF
Thanks everyone for the work so far! I was going to take a look at the tests when I noticed something... the patch executes
hook_block_view_alter()
after the block has been built with\Drupal\Core\Block\BlockPluginInterface::build()
, whereas\Drupal\block\BlockViewBuilder
does the build in a pre-render, after the view alter. And thinking a bit further, any sites with an existinghook_block_view_alter()
might be adding a#pre-render
that expects#block
to be set with the block config entity... and it could explode because we don't have one with LB.So I wonder if we can actually add this block.module hook to layout builder blocks without breaking BC?
Thanks!
- 🇫🇷France paul_leclerc Lausanne Switzerland
I had the same issue #19 🐛 Execute hook_block_view_alter when placing blocks with layout builder Needs work is talking about.
This patch fixed it. #14 🐛 Execute hook_block_view_alter when placing blocks with layout builder Needs workI now have the list of blocks of a layout builder page. in hook_block_view_alter and hook_block_view_BASE_BLOCK_ID_alter
Thanks
- 🇧🇪Belgium Tim Lammar
I had the same issue.
I wanted to hook in on layout builder rendering blocks.
The patch was not yet a fix for me, but it might be edge case.
Technically there is a small issue with this patch.
We are launching an alter hook on block_view, but it is launched during the build of the block.
In most cases, that nuance won't make a difference, but in my case it does as our blocks are loading with lazy loading.
In short that makes it go like this
1. Page load
2. hook_block_build to set placeholders for the blocks.
3. Response
4. Ajax calls to set to contents per block
5. hook_block_view to fill the contents
6. Response per blockIf you aren't using lazy_builder, it doens't matter whether you hook into block_build or block_view.
But to be correct, it has to be block_build as we are in the build stage of layoutbuilder:/** * Builds render arrays for block plugins and sets it on the event. * * @param \Drupal\layout_builder\Event\SectionComponentBuildRenderArrayEvent $event * The section component render event. */ public function onBuildRender(SectionComponentBuildRenderArrayEvent $event) {
Hereby a patch that launches block_build_alter instead of block_view_alter.
With this you can make alterations to the page, based on a block, before the page is loaded. (in our case, a page redirect) - last update
about 1 year ago Patch Failed to Apply - last update
about 1 year ago 30,605 pass - 🇮🇳India Akhil Babu Chengannur
Tested #28 in drupal 10.1.6 and both hook_block_build_alter & hook_block_build_BASE_BLOCK_ID_alter gets called after applying the patch.
Testing steps
- Enable layout builder module and use it for Basic page contenty type. Enable 'Allow each content item to have its layout customized.'
- Create new block content of type "Basic block". Give title and ddescription , the save
- Implement hook_block_build_alter and hook_block_build_BASE_BLOCK_ID_alter to change the content of previous block ($build['content']['body'][0]['#text'] = 'Nex text')
- Create a Basic page content->Edit the layout and place the block.
- Content of the block is not updated as hooks are not fired.
- Now apply the patch #28 ->clear cache and check the previously created basic page node.
- Block content has updated as hooks were fired
+1RTBC - Status changed to RTBC
about 1 year ago 1:23pm 7 December 2023 - Status changed to Needs work
about 1 year ago 1:24pm 7 December 2023 The Needs Review Queue Bot → tested this issue.
While you are making the above changes, we recommend that you convert this patch to a merge request → . Merge requests are preferred over patches. Be sure to hide the old patch files as well. (Converting an issue to a merge request without other contributions to the issue will not receive credit.)
- 🇮🇳India Akhil Babu Chengannur
Akhil Babu → changed the visibility of the branch 3292520-execute-hookblockviewalter-when to hidden.
- 🇮🇳India Akhil Babu Chengannur
Opened the patch in #18 as merge request as per #32
- Status changed to Needs review
about 1 year ago 1:51pm 7 December 2023 - Status changed to Needs work
about 1 year ago 2:07pm 7 December 2023 - 🇺🇸United States smustgrave
This was tagged for tests which are still needed. Before moving to review please check the tags
- First commit to issue fork.
- Merge request !9268Issue #3292520 - Handle block_build and block_view alter hooks → (Open) created by Unnamed author
- 🇺🇦Ukraine piratskul
Here's patch for version 10.3.0 with same changes as in #40 MR for version 11.x
- 🇮🇳India arunkumark Coimbatore
Changing the version back to 11.x, The issue needs to be fixed for Drupal Core 11.x version. We can back-merge the patch for 10.3.x version. Updated PR with test cases.
- Status changed to Needs review
4 months ago 8:01am 22 August 2024 - 🇮🇳India arunkumark Coimbatore
arunkumark → changed the visibility of the branch 3292520-handle-block_build-and-block_view-alter-hooks to hidden.
- 🇮🇳India arunkumark Coimbatore
arunkumark → changed the visibility of the branch 3292520-execute-hookblockviewalter-when to hidden.
- Status changed to Needs work
4 months ago 1:16pm 23 August 2024 - Assigned to shalini_jha
- 🇮🇳India shalini_jha
It seems the "Test-only" test is failing when it shouldn’t.
- 🇮🇳India arunkumark Coimbatore
Resolved most of the Test case issues, few pipeline issues are unable to fix.