symfony form repeated bits -


i've got couple of entities use traits same properties , same behaviour without repeating code.

a example "startdate" , "enddate" blogposts, articles, or whatever want give start/enddate displaying purposes. (please don't ask why want give blogpost enddate).

as can imagine, form elements repeated well.

what best approach prevent repeating of bit of code in formtype's?

i've considered listeners/subscribers, isn't depending on actual data.

i use trait here, , call method in trait. work quite well, might bit weird. also, not use of symfony's form features might want.

is there symfony form feature can use here?

a possible solution using trait.

trait yourrepetitivefieldstypetrait {     public function buildformyourrepetitivefields(formbuilderinterface $builder, array $options)     {         // add form fields     } } 

then include trait in each type need it. , call method in buildform:

$this->buildformyourrepetitivefields($builder, $options); 

the reason different method name avoid clashes when importing in main class.


Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

java.lang.NoClassDefFoundError When Creating New Android Project -

Decoding a Python 2 `tempfile` with python-future -