Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
EventListener mit PRE_SET_DATA-Event in Symfony2
/* ... */
public function buildForm(FormBuilder $builder, array $options)
{
$builder->addEventListener(FormEvents::PRE_SET_DATA,
function (DataEvent $event) use ($builder)
{
$form = $event->getForm();
/* @var \Sperrobjekt\Sf2ttBundle\Entity\Category $data */
$data = $event->getData();
if ($data instanceof \Sperrobjekt\Sf2ttBundle\Entity\Category) {
$label = $data->getName();
$form->add($builder->getFormFactory()->createNamed(
'text',
'Category Name',
null,
array(
'label' => $label,
)
));
}
});
}
/* ... */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment