/** * @param $collection * @param BaseForm $form * @return SymfonyForm * * Extract the collection object from the form */ protected function resolveCollection($collection, BaseForm $form) { if (null === $collection) { throw new \InvalidArgumentException("Missing parameter 'collection' in 'form_collection"); } $sfForm = $form->getForm(); if (!$sfForm->has($collection)) { throw new \InvalidArgumentException(sprintf("Field name '%s' not found in form %s children", $collection, $form->getName())); } /** * Check that the field is a "collection" type */ $collectionConfig = $this->retrieveField($collection, $sfForm->all(), $form->getName()); $fieldType = $collectionConfig->getConfig()->getType(); if ($fieldType->getName() !== static::COLLECTION_TYPE_NAME) { $baseFieldType = $fieldType; $resolved = false; while (null !== $fieldType && !$resolved) { if ($fieldType->getName() !== static::COLLECTION_TYPE_NAME) { $fieldType = $fieldType->getParent(); } } if (!$resolved) { throw new \LogicException(sprintf("The field '%s' is not a collection, it's a '%s'." . "You can't use it with the function 'form_collection' in form '%s'", $collection, $baseFieldType->getName(), $form->getName())); } } return $collectionConfig; }
public function getName() { return $this->form->getName(); }