26 lines
616 B
Plaintext
26 lines
616 B
Plaintext
<?php
|
|
|
|
namespace Trinity\Bundle\UserBundle\Form\EventListener;
|
|
|
|
use Symfony\Component\Form\FormEvent;
|
|
use Symfony\Component\Form\FormEvents;
|
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
|
|
|
class AddCodeFieldSubscriber implements EventSubscriberInterface
|
|
{
|
|
public static function getSubscribedEvents()
|
|
{
|
|
return array(FormEvents::PRE_SET_DATA => 'preSetData');
|
|
}
|
|
|
|
public function preSetData(FormEvent $event)
|
|
{
|
|
$data = $event->getData();
|
|
$form = $event->getForm();
|
|
|
|
if (!$data || !$data->getId()) {
|
|
$form->add('code');
|
|
}
|
|
}
|
|
|
|
} |