Ejemplo n.º 1
0
 /**
  * @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;
 }
Ejemplo n.º 2
0
 public function getName()
 {
     return $this->form->getName();
 }