Closed (outdated)
Project:
Drupal core
Version:
7.x-dev
Component:
forms system
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
8 Jun 2012 at 22:52 UTC
Updated:
18 Aug 2021 at 09:39 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
iLLin commentedI can confirm this with a custom block to and it only happens when you are logged out. Logged in it works as its intended. This is most likely a core bug. Moving there.
Comment #2
iLLin commentedComment #3
iLLin commentedMore information:
Standard block template with form #prefix/#suffix added when logged in:
Same block form output when logged out:
For some reason the prefix/suffix are added outside the block id when not logged in.
Comment #4
doublejosh commentedAs a working around, in my form_alters I've started to put the form suffix on the submit element.
Also placed my form prefix on the first fieldset.
Comment #5
muri commentedForm prefix and suffix properties are for wrapping form items. Rather than above you can wrap like
This will produce
Comment #6
doublejosh commentedWhat's the preferred form prefix/suffix then? Perhaps #type = '#markup' ...something like this:
Comment #7
foopang commentedHi, I found the bug in _block_get_renderable_array() function,
In line 337, the block content is put on the top level of the renderable array:
$build[$key] = $block->content;
And in line 353, the block theme wrapper callback is directly added to the renderable array, any #prefix and #suffix elements will be placed after all theme wrappers of the block content have been rendered, so they are placed outside the block.
To fix this problem, we can just put the block content into a child element of the renderable array in line 337:
$build[$key]['content'] = $block->content;
I've created a patch for this issue, please kindly test!
Comment #8
smira commented#7: form_prefix_elements_placed_outside_block-1623514-7.patch queued for re-testing.
Comment #9
smira commentedrequested a re-test since is seems like the block module has changed quite a bit this past week!
Comment #10
kolier commented#7 works on 7.23.
Comment #11
Anonymous (not verified) commentedchecked ok for #dcprague sprint, still needs further review
Comment #12
reecemarsland commented#7 works for 7.x-dev.
Tested both logged in and logged out forms and both prefix and suffix.
Comment #13
k.skarlatos commentedSteps to reproduce
Comment #14
k.skarlatos commentedApplied #7 using steps in #13 and works as intended.
Comment #15
yurg commented#7 works for me perfectly, save a lot of headaches.
Comment #15.0
yurg commentednote
Comment #16
joekrukosky#7 worked for me as well but if you don't wish to patch core, I got a neat work around from BTMindgrub. Simply render the form in the block:
Comment #17
swim commentedI had to apply this patch (#7) to a number of 7.23 sites and it worked fine across all of them. Thank you @foopang =).
When can we expect to see this committed to core? I'm amazed more people have not encountered this issue.
Comment #18
star-szrIf this is an issue in 8.x as well it needs to be fixed there per the backport policy.
Can we please test this on 8.x? If it's fixed for 8.x then the issue can go back to 7.x and have the 'needs backport to D7' tag removed.
Comment #19
star-szrThis can theoretically be tested using the steps in #13 and the 8.x version of https://drupal.org/project/formblock.
Comment #20
lokapujyai just noticed this problem in my own custom D7 code. Although I'd like to fix it, what could this potentially break in existing D7 modules?
Comment #21
lokapujyaComment #22
lokapujyaIf you look at the D8 search box markup with that patch, you will see that the prefix is inside the block.
Comment #23
lokapujyaThis would need automated tests too. But fixing it would break sites that are relying on the current behavior, so we would need a pretty good change notice too. How do we handle this situation?
Comment #24
garbo commentedA simple solution to this is when you write mymodule_block_view() you put the form in a sub-array within $block['content'] like this:
Comment #25
lokapujyaComment #26
muri commentedI think the form always needs to be rendered before assigned to $block objects content. As $block core below doesn't accept any content if it is not rendered.
As in #16 therefore it should be as below with drupal_render(). Thanks joekrukosky!
Comment #27
jeroentThanks @garbo,
#24 was the solution for my problem.