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.

CommentFileSizeAuthor
#10 poll_post.patch3.97 KBchx
#5 poll_6.patch3.5 KBchx
#4 poll_5.patch3.66 KBchx
inject.patch5.06 KBchx
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

killes@www.drop.org’s picture

Status: Needs review » Needs work

The patch contains some cruft.

killes@www.drop.org’s picture

heh, that actually was supposed to be in there? I think somebody needs some sleep. :P
Anyway, the status is correct.

chx’s picture

Status: Needs work » Needs review

Sleep? 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.

chx’s picture

Title: Allow form element injection -- remove POST from poll » remove POST from poll
FileSize
3.66 KB

simpler version

chx’s picture

FileSize
3.5 KB
chx’s picture

Status: Needs review » Reviewed & tested by the community

I 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.

Dries’s picture

It makes for _less_ readable code. I don't like the fact that the forms API gets more and more obscure.

adrian’s picture

Status: Reviewed & tested by the community » Needs work

i 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 ?

chx’s picture

the 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.

chx’s picture

Status: Needs work » Reviewed & tested by the community
FileSize
3.97 KB

The 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.

Dries’s picture

I like this patch better but leave the final review up to Adrian.

moshe weitzman’s picture

yes, extremely clean.

adrian’s picture

+1

this is a very useful trick, and a way cleaner solution than anything else we have tried.

good work.

Dries’s picture

Status: Reviewed & tested by the community » Fixed

Committed to HEAD. Thanks.

Anonymous’s picture

Status: Fixed » Closed (fixed)