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.
Very often it is asked for to inject elements depending on $_POST . Here is the possibility. Do not overuse!! Elements injected like this can not be form_alter'd . The patch also fixes the problem that the 'Need more choices' checkbox stays ticked.
A minor problem is that we had no good idea for the function name , thus the name form_foo . Better names are warmly welcome.
Comment | File | Size | Author |
---|---|---|---|
#10 | poll_post.patch | 3.97 KB | chx |
#5 | poll_6.patch | 3.5 KB | chx |
#4 | poll_5.patch | 3.66 KB | chx |
inject.patch | 5.06 KB | chx | |
Comments
Comment #1
killes@www.drop.org CreditAttribution: killes@www.drop.org commentedThe patch contains some cruft.
Comment #2
killes@www.drop.org CreditAttribution: killes@www.drop.org commentedheh, that actually was supposed to be in there? I think somebody needs some sleep. :P
Anyway, the status is correct.
Comment #3
chx CreditAttribution: chx commentedSleep? We do not sleep in Vancouver :P anyways, I was sitting next to webchick and even she had no good idea for the name. And frankly, this patch needs a review -- if I set it to needs work (which is also true) noone will check whether it work.s The work neeeded is not a functional one, so we need someone to verify that poll works as intended.
Comment #4
chx CreditAttribution: chx commentedsimpler version
Comment #5
chx CreditAttribution: chx commentedComment #6
chx CreditAttribution: chx commentedI reviewed this quite enough. Why this needs to be in 4.7? First, to provide an example, that's why. Second, this is the way now things should be.
Comment #7
Dries CreditAttribution: Dries commentedIt makes for _less_ readable code. I don't like the fact that the forms API gets more and more obscure.
Comment #8
adrian CreditAttribution: adrian commentedi agree with dries.
i still feel a '#multiple' keyword is the most readable solution.
You had the code almost working in that direction and then decided to rewrite it as this.
do you still have the previous revision from the coffee shop ?
Comment #9
chx CreditAttribution: chx commentedthe particular problem is that how we get the values for #title, #default_value, #value, #description, #dancing_pink_elephant for a particular element. the version Adrian references to used a callback to the original module which was supposed to do it... and now, as I come to think of it, I have another idea... let me cook something.
Comment #10
chx CreditAttribution: chx commentedThe patch builds the necessary fields in advance. When I mentioned this to Adrian he said "sounds quite clean".
If we call form_builder from other function then it's not internal. Thus I removed the underscore from it and added phpdocs.
Comment #11
Dries CreditAttribution: Dries commentedI like this patch better but leave the final review up to Adrian.
Comment #12
moshe weitzman CreditAttribution: moshe weitzman commentedyes, extremely clean.
Comment #13
adrian CreditAttribution: adrian commented+1
this is a very useful trick, and a way cleaner solution than anything else we have tried.
good work.
Comment #14
Dries CreditAttribution: Dries commentedCommitted to HEAD. Thanks.
Comment #15
(not verified) CreditAttribution: commented