Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JuanLuisGarciaBorrego/986f8901b10ce4a7472e to your computer and use it in GitHub Desktop.
Save JuanLuisGarciaBorrego/986f8901b10ce4a7472e to your computer and use it in GitHub Desktop.
AddBameFieldOnlyForCreateNewTaskSusbscriber.php
<?php
namespace JuanLuis\LabBundle\Form\EventListener;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class AddNameFieldOnlyForCreateNewTaskSubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents()
{
return array(FormEvents::PRE_SET_DATA => array('preSetData', 0));
}
public function preSetData(FormEvent $event)
{
$task = $event->getData();
$form = $event->getForm();
if(!$task || null === $task->getId()){
$form->add('name', 'text',
array(
'max_length' => 100
)
);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment