Skip to content

Commit

Permalink
bug #10077 Fix select attributes according to recent Symfony form cha…
Browse files Browse the repository at this point in the history
…nges (Zales0123)

This PR was merged into the 1.2 branch.

Discussion
----------

| Q               | A
| --------------- | -----
| Branch?         | 1.2
| Bug fix?        | yes
| New feature?    | no
| BC breaks?      | no
| Deprecations?   | no
| Related tickets | related to symfony/symfony#29307
| License         | MIT

Due to the latest Symfony 4.1.10/3.4.21 release and changes introduced in linked PR, a bug in select attribute type araised 🌤 Apparently, possible to select values in attribute configuration was saved with `TextType` form type, even though `SelectAttributeValueTranslationsType` should be used. It was somehow parsed before, but know it's not possible and this PR fixes this absurdity 🖖 

Commits
-------

51f7ec2 Fix select attributes according to recent Symfony form changes
b80fa00 Fix test in ResourceBundle (taken from #10062)
  • Loading branch information
pamil committed Jan 8, 2019
2 parents ffc0f8c + b80fa00 commit edddb99
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
Expand Up @@ -36,7 +36,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();

Expand All @@ -57,8 +57,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);
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/Sylius/Bundle/ResourceBundle/test/app/config/routing.yml
Expand Up @@ -4,15 +4,15 @@ app_book:
type: sylius.resource_api

app_book_sortable_index:
path: /books/sortable/
path: /sortable-books/
methods: [GET]
defaults:
_controller: app.controller.book:indexAction
_sylius:
sortable: true

app_book_filterable_index:
path: /books/filterable/
path: /filterable-books/
methods: [GET]
defaults:
_controller: app.controller.book:indexAction
Expand All @@ -24,7 +24,7 @@ app_versioned_book:
prefix: /v{version}

app_create_book_with_custom_factory:
path: /books/create-custom
path: /create-custom-book
methods: [POST]
defaults:
_controller: app.controller.book:createAction
Expand Down
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -223,7 +223,7 @@ public function it_allows_creating_a_book_via_custom_factory()
}
EOT;

$this->client->request('POST', '/books/create-custom', [], [], ['CONTENT_TYPE' => 'application/json'], $data);
$this->client->request('POST', '/create-custom-book', [], [], ['CONTENT_TYPE' => 'application/json'], $data);
$response = $this->client->getResponse();
$this->assertResponse($response, 'books/create_response', Response::HTTP_CREATED);
}
Expand Down

0 comments on commit edddb99

Please sign in to comment.