php - Symfony Form: How to replace form class / retrieve all extra data? -


the symfony 2 form component something. guess know that. trying understand works how seemingly impossible task; , i'm quite experienced @ browsing through codebases.. man, form component.. omg

tl;dr

below details, issue tries ask

  • is possible replace class \symfony\component\form\form?
  • or: how data fields of type form of form?
  • or, related question: how on earth work if $form->add('ss', 'form') - core\formtype class gets involved when retrieve later, instance of \symfony\component\form\form? happen , can maybe overriden uses different class there?

details

the situation

imagine controller receives n deep json payload. payload gets decoded , validated through form. now, of json structure mapped models (doctrine odm entities). sub-properties "hashes" - client allowed post whatever wants there.
"hash" subproperties fields of type form, compound flagged , can have fields.

the problem

bottom line our problem is, "extra fields" not returned $form->getdata(). unable specify fields (and types) don't know come - data part of extradata.

the solution?

so thought - ok - let's modify formfactory it'll return our custom extension of form - 1 returns extradata when getdata called. easy right.? noo, not easy..

my idea let me inspect formfactory, formbuilders, resolvedformtypes, whatnot.. , @ important places (like formbuilder->getform()) - classes want override/replace instanciated static - no usage of dic..(!)

i've read somewhere form component in symfony 2 written devil himself let developer go mad. luckily i'm not mad try replace entire form component myself ;)

jokes aside, when define form (by creating <entity>type class, usertype) defining new type can simple single text input or complex full-fledged form (our usertype before). "real" form (symfony\component\form\form) created type definition:

return $this->container->get('form.factory')->create(     new usertype(), new user(), $options ); 

have evaluated idea create custom form type "extradata"? or maybe can mapped json string that's created client-side javascript before submit.


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -