From 8cad15ef49eecca396cae48cc8204e22909d8f85 Mon Sep 17 00:00:00 2001 From: Mateusz Zalewski Date: Fri, 1 Feb 2019 13:33:05 +0100 Subject: [PATCH] [1.1] Fix select attributes according to recent Symfony form changes --- .../SelectAttributeChoicesCollectionType.php | 9 ++++++--- .../Bundle/ResourceBundle/test/app/config/routing.yml | 4 ++-- .../test/src/Tests/Controller/BookApiTest.php | 8 ++++---- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/Sylius/Bundle/AttributeBundle/Form/Type/AttributeType/Configuration/SelectAttributeChoicesCollectionType.php b/src/Sylius/Bundle/AttributeBundle/Form/Type/AttributeType/Configuration/SelectAttributeChoicesCollectionType.php index 19ba9129589..8fa5d74b712 100644 --- a/src/Sylius/Bundle/AttributeBundle/Form/Type/AttributeType/Configuration/SelectAttributeChoicesCollectionType.php +++ b/src/Sylius/Bundle/AttributeBundle/Form/Type/AttributeType/Configuration/SelectAttributeChoicesCollectionType.php @@ -41,7 +41,7 @@ public function __construct(TranslationLocaleProviderInterface $localeProvider) */ public function buildForm(FormBuilderInterface $builder, array $options): void { - $builder->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event) { + $builder->addEventListener(FormEvents::SUBMIT, function (FormEvent $event) { $data = $event->getData(); $form = $event->getForm(); @@ -62,8 +62,11 @@ public function buildForm(FormBuilderInterface $builder, array $options): void $fixedData[$newKey] = $this->resolveValues($values); if ($form->offsetExists($key)) { - $form->offsetUnset($key); - $form->offsetSet(null, $newKey); + $type = get_class($form->get($key)->getConfig()->getType()->getInnerType()); + $options = $form->get($key)->getConfig()->getOptions(); + + $form->remove($key); + $form->add($newKey, $type, $options); } } diff --git a/src/Sylius/Bundle/ResourceBundle/test/app/config/routing.yml b/src/Sylius/Bundle/ResourceBundle/test/app/config/routing.yml index 94e736491e3..5cede2d74f0 100644 --- a/src/Sylius/Bundle/ResourceBundle/test/app/config/routing.yml +++ b/src/Sylius/Bundle/ResourceBundle/test/app/config/routing.yml @@ -4,7 +4,7 @@ app_book: type: sylius.resource_api app_book_sortable_index: - path: /books/sortable/ + path: /sortable-books/ methods: [GET] defaults: _controller: app.controller.book:indexAction @@ -12,7 +12,7 @@ app_book_sortable_index: sortable: true app_book_filterable_index: - path: /books/filterable/ + path: /filterable-books/ methods: [GET] defaults: _controller: app.controller.book:indexAction diff --git a/src/Sylius/Bundle/ResourceBundle/test/src/Tests/Controller/BookApiTest.php b/src/Sylius/Bundle/ResourceBundle/test/src/Tests/Controller/BookApiTest.php index 10e3f663017..de2386377e8 100644 --- a/src/Sylius/Bundle/ResourceBundle/test/src/Tests/Controller/BookApiTest.php +++ b/src/Sylius/Bundle/ResourceBundle/test/src/Tests/Controller/BookApiTest.php @@ -161,7 +161,7 @@ public function it_does_not_apply_sorting_for_un_existing_field() { $this->loadFixturesFromFile('more_books.yml'); - $this->client->request('GET', '/books/sortable/', ['sorting' => ['name' => 'DESC']]); + $this->client->request('GET', '/sortable-books/', ['sorting' => ['name' => 'DESC']]); $response = $this->client->getResponse(); $this->assertResponseCode($response, Response::HTTP_OK); @@ -174,7 +174,7 @@ public function it_does_not_apply_filtering_for_un_existing_field() { $this->loadFixturesFromFile('more_books.yml'); - $this->client->request('GET', '/books/filterable/', ['criteria' => ['name' => 'John']]); + $this->client->request('GET', '/filterable-books/', ['criteria' => ['name' => 'John']]); $response = $this->client->getResponse(); $this->assertResponseCode($response, Response::HTTP_OK); @@ -187,7 +187,7 @@ public function it_applies_sorting_for_existing_field() { $this->loadFixturesFromFile('more_books.yml'); - $this->client->request('GET', '/books/sortable/', ['sorting' => ['id' => 'DESC']]); + $this->client->request('GET', '/sortable-books/', ['sorting' => ['id' => 'DESC']]); $response = $this->client->getResponse(); $this->assertResponseCode($response, Response::HTTP_OK); @@ -200,7 +200,7 @@ public function it_applies_filtering_for_existing_field() { $this->loadFixturesFromFile('more_books.yml'); - $this->client->request('GET', '/books/filterable/', ['criteria' => ['author' => 'J.R.R. Tolkien']]); + $this->client->request('GET', '/filterable-books/', ['criteria' => ['author' => 'J.R.R. Tolkien']]); $response = $this->client->getResponse(); $this->assertResponseCode($response, Response::HTTP_OK);