From a0796f422da692fa68b1e08fd259266c92e151d1 Mon Sep 17 00:00:00 2001 From: NicolasBadey Date: Wed, 20 Feb 2013 12:31:17 +0100 Subject: [PATCH 1/7] fix --- Serializer/XmlFormViewSerializer.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Serializer/XmlFormViewSerializer.php b/Serializer/XmlFormViewSerializer.php index 055542e..3d9726c 100644 --- a/Serializer/XmlFormViewSerializer.php +++ b/Serializer/XmlFormViewSerializer.php @@ -480,10 +480,8 @@ protected function serializeFormRows(\DOMElement $parentElement, FormView $view, protected function serializeCollectionWidget(\DOMElement $parentElement, FormView $view, $variables) { if (isset($variables['prototype'])) { - // TODO test this ? - var_dump($variables['prototype']);exit; $variables['attr'] = array_merge($variables['attr'], array( - 'data-prototype' => $this->renderer->searchAndRenderBlock($variables['prototype'], 'row'), + 'data-prototype' => $this->serializeBlock($parentElement,$variables['prototype'], 'row'), )); } From 66aa62bdb0ba63db9c1b6e67567d23ca899b7a35 Mon Sep 17 00:00:00 2001 From: Adrien Brault Date: Wed, 20 Feb 2013 14:51:30 +0100 Subject: [PATCH 2/7] Fix 2.2 build --- .travis.yml | 2 +- Tests/Functional/config/config.yml | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index ac9f3a8..4db50ea 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,7 +9,7 @@ env: before_script: - wget http://getcomposer.org/composer.phar - - php composer.phar require symfony/framework-bundle:${SYMFONY_VERSION} + - php composer.phar require symfony/symfony:${SYMFONY_VERSION} - php composer.phar --dev install script: diff --git a/Tests/Functional/config/config.yml b/Tests/Functional/config/config.yml index c2cacaf..465065e 100644 --- a/Tests/Functional/config/config.yml +++ b/Tests/Functional/config/config.yml @@ -7,3 +7,4 @@ framework: resource: "%kernel.root_dir%/config/routing.yml" form: ~ validation: ~ + csrf_protection: false From 005f191722fb719e2ca248bbbf84f0af1c239a13 Mon Sep 17 00:00:00 2001 From: NicolasBadey Date: Wed, 20 Feb 2013 12:31:17 +0100 Subject: [PATCH 3/7] fix --- Serializer/XmlFormViewSerializer.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Serializer/XmlFormViewSerializer.php b/Serializer/XmlFormViewSerializer.php index 055542e..3d9726c 100644 --- a/Serializer/XmlFormViewSerializer.php +++ b/Serializer/XmlFormViewSerializer.php @@ -480,10 +480,8 @@ protected function serializeFormRows(\DOMElement $parentElement, FormView $view, protected function serializeCollectionWidget(\DOMElement $parentElement, FormView $view, $variables) { if (isset($variables['prototype'])) { - // TODO test this ? - var_dump($variables['prototype']);exit; $variables['attr'] = array_merge($variables['attr'], array( - 'data-prototype' => $this->renderer->searchAndRenderBlock($variables['prototype'], 'row'), + 'data-prototype' => $this->serializeBlock($parentElement,$variables['prototype'], 'row'), )); } From c0593a31d62771a08854327ac8b0388c9f9e0eb7 Mon Sep 17 00:00:00 2001 From: NicolasBadey Date: Thu, 21 Feb 2013 12:15:15 +0100 Subject: [PATCH 4/7] add collection test --- .../Serializer/XmlFormViewSerializerTest.php | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/Tests/Functional/Serializer/XmlFormViewSerializerTest.php b/Tests/Functional/Serializer/XmlFormViewSerializerTest.php index fa663a6..2536c18 100644 --- a/Tests/Functional/Serializer/XmlFormViewSerializerTest.php +++ b/Tests/Functional/Serializer/XmlFormViewSerializerTest.php @@ -4,6 +4,10 @@ use FSC\HateoasBundle\Tests\Functional\TestCase; use FSC\HateoasBundle\Serializer\XmlFormViewSerializer; +use Symfony\Component\OptionsResolver\OptionsResolverInterface; +use Symfony\Component\Form\AbstractType; +use Symfony\Component\Form\FormBuilderInterface; + /** * @group functional @@ -106,6 +110,32 @@ public function testFileType() , $formElement); } + public function testCollectionType() + { + $formFactory = $this->getKernel()->getContainer()->get('form.factory'); + + $form = $formFactory->createBuilder('form') + ->add('service', 'collection', [ + 'type' => new availabilityFormType(), + 'allow_add' => true + ]) + ->getForm(); + + $formView = $form->createView(); + + $xmlFormViewSerializer = new XmlFormViewSerializer(); + + $xmlFormViewSerializer->serialize($formView, $formElement = $this->createFormElement()); + + $this->assertXmlElementEquals(<< + + + +XML + , $formElement); + } + public function testDateFields() { $formFactory = $this->getKernel()->getContainer()->get('form.factory'); @@ -398,3 +428,23 @@ protected function createFormElement() return $domDocument->createElement('form'); } } + +class availabilityFormType extends AbstractType +{ + + public function buildForm(FormBuilderInterface $builder, array $options) + { + $builder->add('timeId'); + $builder->add('dayId'); + } + + public function setDefaultOptions(OptionsResolverInterface $resolver) + { + $resolver->setDefaults(array()); + } + public function getName() + { + return 'availability'; + } + +} \ No newline at end of file From 48ffa0a19cf93ea90a2ed464088531152a5a7fb4 Mon Sep 17 00:00:00 2001 From: NicolasBadey Date: Thu, 21 Feb 2013 12:25:32 +0100 Subject: [PATCH 5/7] 5.3 compatiblity in collection test --- Tests/Functional/Serializer/XmlFormViewSerializerTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/Functional/Serializer/XmlFormViewSerializerTest.php b/Tests/Functional/Serializer/XmlFormViewSerializerTest.php index 2536c18..7c6bf15 100644 --- a/Tests/Functional/Serializer/XmlFormViewSerializerTest.php +++ b/Tests/Functional/Serializer/XmlFormViewSerializerTest.php @@ -115,10 +115,10 @@ public function testCollectionType() $formFactory = $this->getKernel()->getContainer()->get('form.factory'); $form = $formFactory->createBuilder('form') - ->add('service', 'collection', [ + ->add('service', 'collection', array( 'type' => new availabilityFormType(), 'allow_add' => true - ]) + )) ->getForm(); $formView = $form->createView(); From df99e8cba17fe145ef868833ac97f823647810e5 Mon Sep 17 00:00:00 2001 From: NicolasBadey Date: Tue, 12 Mar 2013 10:55:00 +0100 Subject: [PATCH 6/7] data-prototype --- Serializer/XmlFormViewSerializer.php | 22 +++++++++++++++---- .../Serializer/XmlFormViewSerializerTest.php | 6 +++-- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/Serializer/XmlFormViewSerializer.php b/Serializer/XmlFormViewSerializer.php index 3d9726c..9b64fd5 100644 --- a/Serializer/XmlFormViewSerializer.php +++ b/Serializer/XmlFormViewSerializer.php @@ -480,12 +480,26 @@ protected function serializeFormRows(\DOMElement $parentElement, FormView $view, protected function serializeCollectionWidget(\DOMElement $parentElement, FormView $view, $variables) { if (isset($variables['prototype'])) { - $variables['attr'] = array_merge($variables['attr'], array( - 'data-prototype' => $this->serializeBlock($parentElement,$variables['prototype'], 'row'), - )); + $this->serializePrototype($parentElement, $variables); + } else { + $this->serializeFormWidget($parentElement, $view, $variables); } + } + + protected function serializePrototype(\DOMElement $parentElement, $variables) + { + $document = new \DOMDocument('1.0', 'UTF-8'); + + $divElement = $document->createElement('div'); + $divElement->setAttribute('id',$variables['id'].'___name__'); + + $this->serializeBlock($divElement,$variables['prototype'], 'row'); + + $ulElement = $parentElement->ownerDocument->createElement('ul'); + $ulElement->setAttribute('id',$variables['id']); + $ulElement->setAttribute('data-prototype', htmlentities($document->saveHTML($divElement), ENT_QUOTES, 'UTF-8')); - $this->serializeFormWidget($parentElement, $view, $variables); + $parentElement->appendChild($ulElement); } /* diff --git a/Tests/Functional/Serializer/XmlFormViewSerializerTest.php b/Tests/Functional/Serializer/XmlFormViewSerializerTest.php index 7c6bf15..2541454 100644 --- a/Tests/Functional/Serializer/XmlFormViewSerializerTest.php +++ b/Tests/Functional/Serializer/XmlFormViewSerializerTest.php @@ -129,8 +129,7 @@ public function testCollectionType() $this->assertXmlElementEquals(<< - - +
    XML , $formElement); @@ -138,6 +137,9 @@ public function testCollectionType() public function testDateFields() { + // force locale for PHP_INTL DateTime + locale_set_default('en-US'); + $formFactory = $this->getKernel()->getContainer()->get('form.factory'); $form = $formFactory->createBuilder('form') ->add('publishedAt', 'date', array( From 0709cb3b3c014d91c82c898277b27eb0a0fb31eb Mon Sep 17 00:00:00 2001 From: NicolasBadey Date: Tue, 12 Mar 2013 12:01:39 +0100 Subject: [PATCH 7/7] data-prototype refactoring --- Serializer/XmlFormViewSerializer.php | 50 ++++++++++++++++------------ 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/Serializer/XmlFormViewSerializer.php b/Serializer/XmlFormViewSerializer.php index 9b64fd5..9b053c0 100644 --- a/Serializer/XmlFormViewSerializer.php +++ b/Serializer/XmlFormViewSerializer.php @@ -200,26 +200,30 @@ protected function serializeWidgetSimple(\DOMElement $parentElement, FormView $v */ protected function addWidgetAttributes(\DOMElement $widgetElement, FormView $view, $variables) { - $widgetElement->setAttribute('name', $variables['full_name']); + if (!isset($variables['prototype'])) { + $widgetElement->setAttribute('name', $variables['full_name']); - if ($variables['read_only']) { - $widgetElement->setAttribute('readonly', 'readonly'); - } + if ($variables['read_only']) { + $widgetElement->setAttribute('readonly', 'readonly'); + } - if ($variables['disabled']) { - $widgetElement->setAttribute('disabled', 'disabled'); - } + if ($variables['disabled']) { + $widgetElement->setAttribute('disabled', 'disabled'); + } - if ($variables['required']) { - $widgetElement->setAttribute('required', 'required'); - } + if ($variables['required']) { + $widgetElement->setAttribute('required', 'required'); + } - if ($variables['max_length']) { - $widgetElement->setAttribute('maxlength', $variables['max_length']); - } + if ($variables['max_length']) { + $widgetElement->setAttribute('maxlength', $variables['max_length']); + } - if ($variables['pattern']) { - $widgetElement->setAttribute('pattern', $variables['pattern']); + if ($variables['pattern']) { + $widgetElement->setAttribute('pattern', $variables['pattern']); + } + } else { + $widgetElement->setAttribute('id', $variables['id']); } foreach ($variables['attr'] as $name => $value) { @@ -480,13 +484,13 @@ protected function serializeFormRows(\DOMElement $parentElement, FormView $view, protected function serializeCollectionWidget(\DOMElement $parentElement, FormView $view, $variables) { if (isset($variables['prototype'])) { - $this->serializePrototype($parentElement, $variables); - } else { - $this->serializeFormWidget($parentElement, $view, $variables); + $this->serializePrototype($parentElement, $view, $variables); } + $this->serializeFormWidget($parentElement, $view, $variables); + } - protected function serializePrototype(\DOMElement $parentElement, $variables) + protected function serializePrototype(\DOMElement $parentElement, FormView $view, $variables) { $document = new \DOMDocument('1.0', 'UTF-8'); @@ -496,8 +500,12 @@ protected function serializePrototype(\DOMElement $parentElement, $variables) $this->serializeBlock($divElement,$variables['prototype'], 'row'); $ulElement = $parentElement->ownerDocument->createElement('ul'); - $ulElement->setAttribute('id',$variables['id']); - $ulElement->setAttribute('data-prototype', htmlentities($document->saveHTML($divElement), ENT_QUOTES, 'UTF-8')); + + $variables['attr'] = array_merge($variables['attr'], array( + 'data-prototype' => htmlentities($document->saveHTML($divElement), ENT_QUOTES, 'UTF-8') + )); + + $this->addWidgetAttributes($ulElement, $view, $variables); $parentElement->appendChild($ulElement); }