public function __construct(FormFactoryInterface $factory, array $prototypes, array $options = array(), $allowAdd = false, $allowDelete = false) { $this->factory = $factory; foreach ($prototypes as $prototype) { $dataClass = $prototype->getConfig()->getDataClass(); $type = $prototype->getConfig()->getType(); $typeKey = $type instanceof ResolvedFormTypeInterface ? $type->getName() : $type; $this->typeMap[$typeKey] = $type; $this->classMap[$dataClass] = $type; } $defaultType = reset($prototypes)->getConfig()->getType()->getName(); parent::__construct($defaultType, $options, $allowAdd, $allowDelete); }
/** * @param array $prototypes * @param array $options * @param bool $allowAdd * @param bool $allowDelete * @param bool $deleteEmpty * @throws \InvalidArgumentException */ public function __construct(array $prototypes, array $options = array(), $allowAdd = false, $allowDelete = false, $deleteEmpty = false) { foreach ($prototypes as $prototype) { /** @var FormInterface $prototype */ $dataClass = $prototype->getConfig()->getOption('data_class'); if (is_null($dataClass)) { throw new \InvalidArgumentException("Only form types with data_class are supported!"); } $type = $prototype->getConfig()->getType()->getInnerType(); $key = $type instanceof FormTypeInterface ? $type->getName() : $type; $this->typeMap[$key] = $type; $this->classMap[$dataClass] = $type; } parent::__construct(null, $options, $allowAdd, $allowDelete); }
/** * @param array<FormInterface> $prototypes * @param array $options * @param bool $allowAdd * @param bool $allowDelete * @param string $typeFieldName * @param string $indexProperty */ public function __construct(array $prototypes, array $options = array(), $allowAdd = false, $allowDelete = false, $typeFieldName = '_type', $indexProperty = null) { $this->typeFieldName = $typeFieldName; $this->indexProperty = $indexProperty; $this->propertyAccessor = PropertyAccess::createPropertyAccessor(); $defaultType = null; foreach ($prototypes as $prototype) { /** @var FormInterface $prototype */ $modelClass = $prototype->getConfig()->getOption('model_class'); $type = $prototype->getConfig()->getType()->getInnerType(); if (null === $defaultType) { $defaultType = $type; } $typeKey = $type instanceof FormTypeInterface ? $type->getName() : $type; $this->typeMap[$typeKey] = $type; $this->classMap[$modelClass] = $type; } parent::__construct($defaultType, $options, $allowAdd, $allowDelete); }
public function testOnSubmitDealsWithArrayBackedIteratorAggregate() { $this->form->add($this->getForm('1')); $data = new ArrayCollection(array(0 => 'first', 1 => 'second', 2 => 'third')); $event = new FormEvent($this->form, $data); $listener = new ResizeFormListener('text', array(), false, true); $listener->onSubmit($event); $this->assertArrayNotHasKey(0, $event->getData()); $this->assertArrayNotHasKey(2, $event->getData()); }
public function testOnBindNormDataDealsWithNullData() { $this->form->add($this->getForm('1')); $data = null; $event = new FilterDataEvent($this->form, $data); $listener = new ResizeFormListener($this->factory, 'text', array(), false, true); $listener->onBindNormData($event); $this->assertEquals(array(), $event->getData()); }