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.
SystemMainBlock::build does not always return an array.
But documentation clearly says it should:
https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Block%21B...
It can produce errors like this:
https://www.drupal.org/node/2812721
Comment | File | Size | Author |
---|---|---|---|
#3 | systemmainblock_build-2885370-3.patch | 514 bytes | jiv_e |
Comments
Comment #2
jiv_e CreditAttribution: jiv_e as a volunteer and at LilDrop Consulting commentedComment #3
jiv_e CreditAttribution: jiv_e as a volunteer and at LilDrop Consulting commentedComment #4
jiv_e CreditAttribution: jiv_e as a volunteer and at LilDrop Consulting commentedComment #5
Dinesh18 CreditAttribution: Dinesh18 as a volunteer commentedI have verified the API and the function doesn't return array. I manually reviewed the patch and it looks like the solution provided by you is perfect.
+1 to RTBC. Let's wait for some other to review the patch as well.
Comment #6
BR0kENhttps://www.drupal.org/node/2819219#comment-11767286
Comment #8
borisson_Actually - reading the other issue - it seems like this was already fixed there. I think that means we can close this issue. The original proposed fix in that issue was the same as the one proposed here.
Comment #9
jiv_e CreditAttribution: jiv_e as a volunteer and at LilDrop Consulting commented@borisson_ Thanks for taking this up! I quess you refer to this issue: https://www.drupal.org/node/2819219
The original fix was the same, but @xjm reverted it. See https://www.drupal.org/node/2819219#comment-11767286.
So this is still not fixed - reopening.
As one downside of the current solution is that we have to mention in our documentation that it's possible SystemMainBlock::build to return something else than an array. See more detailed argumentation here. So either we fix the docs or change the solution.
Comment #10
borisson_@jiv_e I read your response there again and read the other comments as well, looks like Tim is picking this up over in #2825497: SystemMainBlock only functions when used by block.module, that seems like a better solution (making sure main content can only be placed trough the block system). In any case - we don't need 3 issues about this one usecase.
If we want to also use this issue, I'd suggest throwing the exception instead.
Comment #11
tim.plunkett#2825497: SystemMainBlock only functions when used by block.module is the duplicate core issue.
Comment #12
joseph.olstadjust fyi
patch still applies cleanly to 9.1.x
Comment #13
joseph.olstadpatch still applies cleanly to 9.1.x - triggering
patch still applies cleanly to 9.0.x - triggering
patch still applies cleanly to 8.9.x - triggering
marking this as needs review
setting other issue as duplicate. other issue patch no longer applies and fails testing.
this patch passed tests last time
Comment #14
tim.plunkettClosing this one as a duplicate of #3164389: Enforce block plugins returning an array, an issue that has test coverage and only needs review.
Comment #15
tim.plunkettComment #16
joseph.olstadThanks, I got tripped up because the correct parent was not linked.
adding the correct parent duplicate issue