Created
April 26, 2013 18:22
-
-
Save dionisos2/5469308 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Ukratio\TrouveToutBundle\Form\Type; | |
use Symfony\Component\Form\AbstractType; | |
use Symfony\Component\Form\FormInterface; | |
use Symfony\Component\Form\FormBuilderInterface; | |
use Symfony\Component\Form\FormView; | |
use Symfony\Component\OptionsResolver\OptionsResolverInterface; | |
use Ukratio\TrouveToutBundle\Form\EventListener\AddOwnerElementSubscriber; | |
use Ukratio\TrouveToutBundle\Form\EventListener\AddChildElementSubscriber; | |
use Ukratio\TrouveToutBundle\Form\EventListener\AddElementSubscriber; | |
use Ukratio\TrouveToutBundle\Form\DataTransformer\TrueElementToElementTransformer; | |
use Ukratio\TrouveToutBundle\Entity\Element; | |
use Ukratio\TrouveToutBundle\Entity\Type; | |
use Ukratio\TrouveToutBundle\Entity\ConceptRepository; | |
use Ukratio\TrouveToutBundle\Service\CaractTypeManager; | |
use Doctrine\ORM\EntityManager; | |
class ElementType extends AbstractType | |
{ | |
private $em; | |
private $conceptRepo; | |
private $caractTypeManager; | |
public function __construct(EntityManager $em, ConceptRepository $conceptRepo, CaractTypeManager $caractTypeManager) | |
{ | |
$this->em = $em; | |
$this->conceptRepo = $conceptRepo; | |
$this->caractTypeManager = $caractTypeManager; | |
} | |
public function buildForm(FormBuilderInterface $builder, array $options) | |
{ | |
$type = Type::getEnumerator($options['typeOfValue']); | |
$builder->addEventSubscriber(new AddElementSubscriber($builder->getFormFactory(), $this->em, $this->conceptRepo, $type, $this->caractTypeManager)); | |
$builder->addEventSubscriber(new AddOwnerElementSubscriber($builder->getFormFactory(), $this->em)); | |
$builder->addEventSubscriber(new AddChildElementSubscriber($builder->getFormFactory(), $this->em, $type, $this->caractTypeManager)); | |
$builder->addModelTransformer(new TrueElementToElementTransformer($this->em)); | |
} | |
public function setDefaultOptions(OptionsResolverInterface $resolver) | |
{ | |
$resolver->setDefaults(array( | |
'data_class' => 'Ukratio\TrouveToutBundle\Entity\Element', | |
'constraintOnValue' => false, | |
'typeOfValue' => 'name', | |
)); | |
} | |
public function getName() | |
{ | |
return 'TrouveTout_Element'; | |
} | |
public function buildView(FormView $view, FormInterface $form, array $options) | |
{ | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CaractsManager.prototype.getOrBuildChildForm = function (caractForm, index) { | |
var childFormSelect; | |
var type; | |
var childFormSelectDiv; | |
childFormSelect = this.getChildForm(caractForm); | |
if (childFormSelect.length > 0) { | |
return childFormSelect; | |
} else { | |
type = caractForm.find('[id$=type]').val(); | |
childFormSelectDiv = this.prototype_specify[type].replace(/childElement/g, 'caracts_' + (index).toString() + '_value_childElement'); | |
childFormSelectDiv = childFormSelectDiv.replace(/(name=.*?)\[.*?\]/g, '$1[caracts][' + (index).toString() + '][value][childElement]'); | |
caractForm.find('[id$=value_value]').parent().parent().parent().find('div:first').prepend(childFormSelectDiv); | |
childFormSelect = this.getChildForm(caractForm); | |
return childFormSelect; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment