/**
  * Insert entity identifier hidden field into form.
  *
  * This field is required in order to UniqueEntity constraint worked
  * properly on client side with update operation.
  *
  * @param    FormEvent    $event
  */
 public function preSetData(FormEvent $event)
 {
     $data = $event->getData();
     $form = $event->getForm();
     $config = $form->getConfig();
     // This if statement let's us skip right over the null condition.
     if (null === $data || !is_object($data)) {
         return;
     }
     if ($config->getOption('compound') && $this->jsfv->hasUniqueEntityConstraint(get_class($data))) {
         //Backward compability
         $options = array();
         if ($config->hasOption('mapped')) {
             $options['mapped'] = false;
         }
         if ($config->hasOption('auto_initialize')) {
             $options['auto_initialize'] = false;
         }
         //When entity is updated UniqueEntity constraint should ignore
         //entity with the same primary key id
         $identifierField = $this->jsfv->getParameter('identifier_field');
         $form->add($this->factory->createNamed($identifierField, 'hidden', json_encode($this->jsfv->getEntityIdentifierValue($data)), $options));
     }
 }
 /**
  * @param ContainerInterface       $container
  * @param MetadataFactoryInterface $metadataFactory
  */
 public function __construct(ContainerInterface $container, MetadataFactoryInterface $metadataFactory)
 {
     parent::__construct($container);
     $this->metadataFactory = $metadataFactory;
 }