Skip to content

Instantly share code, notes, and snippets.

@rdohms
Created December 5, 2012 15:22
Show Gist options
  • Select an option

  • Save rdohms/4216484 to your computer and use it in GitHub Desktop.

Select an option

Save rdohms/4216484 to your computer and use it in GitHub Desktop.
Binding Events in Parent Form
<?php
abstract class MyAbstractType extends AbstractType
{
/** CODE */
}
<?php
class MyFormType extends MyAbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add();
...
}
}
@rdohms

rdohms commented Dec 5, 2012

Copy link
Copy Markdown
Author

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?

@webmozart

Copy link
Copy Markdown

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.

@webmozart

Copy link
Copy Markdown

*extend, not implement

@rdohms

rdohms commented Dec 5, 2012

Copy link
Copy Markdown
Author

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