public function testSerialize() { $form = $form = $this->get('form.factory')->createBuilder('form')->add('name', 'text')->add('description', 'textarea')->getForm(); $form->bind(array('name' => 'Adrien', 'description' => 'THIS IS SPARTA')); $formNormalizer = new FormNormalizer(); $normalizedForm = $formNormalizer->normalize($form); $this->assertSerializedXmlEquals('<form> <input type="text" value="Adrien" name="form[name]" required="required"/> <textarea name="form[description]" required="required"><![CDATA[THIS IS SPARTA]]></textarea> </form>', $normalizedForm); }
public function normalizeEntityCollection($entity, $rel, Pagerfanta $pager, FormDescription $formDescription) { $configurationEntityCollection = $this->getConfigurationEntityCollections()[$rel]; if (isset($configurationEntityCollection['can_see']) && !$configurationEntityCollection['can_see']($this->securityContext, $entity)) { throw new AccessDeniedException(); } $entityCollectionRepresentationClass = $configurationEntityCollection['representation_class']; $entityCollectionRepresentation = new $entityCollectionRepresentationClass(); $this->configureCollectionRepresentation($entityCollectionRepresentation, $pager, $entity, $rel); // Results $entityCollectionRepresentation->results = array(); foreach ($pager->getCurrentPageResults() as $entity) { $class = ClassUtils::getRealClass(get_class($entity)); $entityResource = $this->container->get($configurationEntityCollection['resources'][$class]); $entityCollectionRepresentation->results[] = $entityResource->normalizeEntity($entity, true); } // Search form $entityCollectionRepresentation->addForm($this->formNormalizer->normalizeFormDescription($formDescription)); return $entityCollectionRepresentation; }