diff --git a/src/CL/CustomFieldsBundle/Form/DataTransformer/JsonCustomFieldToArrayTransformer.php b/src/CL/CustomFieldsBundle/Form/DataTransformer/JsonCustomFieldToArrayTransformer.php index f586327df..f314fe942 100644 --- a/src/CL/CustomFieldsBundle/Form/DataTransformer/JsonCustomFieldToArrayTransformer.php +++ b/src/CL/CustomFieldsBundle/Form/DataTransformer/JsonCustomFieldToArrayTransformer.php @@ -65,7 +65,12 @@ class JsonCustomFieldToArrayTransformer implements DataTransformerInterface { if(array_key_exists($key, $this->customField)) { $type = $this->customField[$key]->getType(); if(strpos($type,'ManyToOne') === 0) { - $entityClass = substr($type, 10, -1); + if(strpos($type,'ManyToOnePersist') ===0) { + $entityClass = substr($type, 17, -1); + } else { + $entityClass = substr($type, 10, -1); + } + $customFieldsArrayRet[$key] = $this->om ->getRepository('CLCustomFieldsBundle:' . $entityClass) ->findOneById($value); @@ -104,8 +109,24 @@ class JsonCustomFieldToArrayTransformer implements DataTransformerInterface { if(array_key_exists($key, $this->customField)) { $type = $this->customField[$key]->getType(); if(strpos($type,'ManyToOne') === 0) { + // pour le manytoone() faire + // un update du form en js ? : http://symfony.com/fr/doc/current/cookbook/form/form_collections.html + // //$entityClass = substr($type, 10, -1); //echo $entityClasss; + if(strpos($type, 'ManyToOnePersist') === 0) { + $this->om->persist($value); // pas bon ici + // LE PERSIST NE SERT QUE LA PREMIERE FOIS + // plutot le mettre dans une var temporaire de adress + // et faire le persist qd fait sur l'obj parent + // regarder : http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/events.html + // ou : http://symfony.com/doc/current/cookbook/doctrine/event_listeners_subscribers.html + // dans yml : + // lifecycleCallbacks: + // prePersist: [ doStuffOnPrePersist, doOtherStuffOnPrePersist ] + $this->om->flush(); // sinon l'id pose pbm + } + $customFieldsArrayRet[$key] = $value->getId(); $traited = true; } diff --git a/src/CL/CustomFieldsBundle/Form/Type/CustomFieldType.php b/src/CL/CustomFieldsBundle/Form/Type/CustomFieldType.php index 1d2936331..67c52c20b 100644 --- a/src/CL/CustomFieldsBundle/Form/Type/CustomFieldType.php +++ b/src/CL/CustomFieldsBundle/Form/Type/CustomFieldType.php @@ -15,6 +15,7 @@ use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; use CL\CustomFieldsBundle\Form\DataTransformer\JsonCustomFieldToArrayTransformer; use Doctrine\Common\Persistence\ObjectManager; +use CL\CustomFieldsBundle\Form\AdressType; class CustomFieldType extends AbstractType { @@ -43,7 +44,10 @@ class CustomFieldType extends AbstractType 'class' => 'CLCustomFieldsBundle:Adress', 'property' => 'data', )); - } else { + } else if ($cf->getType() === 'ManyToOnePersist(Adress)') { + $builder->add($cf->getLabel(), new AdressType()); + } + else { $builder->add($cf->getLabel(), $cf->getType()); } }