Created
December 5, 2012 15:22
-
-
Save rdohms/4216484 to your computer and use it in GitHub Desktop.
Binding Events in Parent Form
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
abstract class MyAbstractType extends AbstractType | |
{ | |
/** CODE */ | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class MyFormType extends MyAbstractType | |
{ | |
public function buildForm(FormBuilderInterface $builder, array $options) | |
{ | |
$builder->add(); | |
... | |
} | |
} |
Why don't you use the form's native inheritance mechanism? I.e., let both types implementAbstractType
and define getParent()
in MyFormType
to return the name of MyAbstractType
(defined in its getName()
). This would solve your problem.
*extend, not implement
Thanks, that is an idea.
Relying on the getParent still leaves me with the possibility of human error if the dev forgets to do that.
But since this is a service I may be able to do some smart juggling and force this to be called by the app itself.
Will try it.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Question:
What can i do in MyAbstractType to set a PRE_SET_DATA event without having to redefine buildForm in MyFormType and add a parent:: call? Is there any other way to guarantee the presence of the event binding in case of inheritance?