Fix BC Break in SelectAttributeChoicesCollectionType

This commit is contained in:
Jan Goralski 2023-08-17 14:58:50 +02:00
parent f297799825
commit a9546e0081
No known key found for this signature in database
GPG key ID: 95D91BA380F31EDD
4 changed files with 26 additions and 5 deletions

View file

@ -1,6 +1,8 @@
# UPGRADE FROM `v1.12.9` TO `v1.12.10`
1. The `Sylius\Bundle\AttributeBundle\Form\Type\AttributeType\Configuration\SelectAttributeChoicesCollectionType` constructor has been removed as it is not used anymore.
1. The `Sylius\Bundle\AttributeBundle\Form\Type\AttributeType\Configuration\SelectAttributeChoicesCollectionType` only
constructor argument has been made optional and is `null` by default, subsequently the first argument of
`sylius.form.type.attribute_type.select.choices_collection` has been removed.
# UPGRADE FROM `v1.12.8` TO `v1.12.9`

View file

@ -1,7 +1,7 @@
@managing_product_attributes
Feature: Seeing correct select attribute values in different locale than default one
In order to see correct attribute values in different locale than default one
As and Administrator
As an Administrator
I should be able to create attribute with values in different locale than default one
Background:
@ -16,4 +16,4 @@ Feature: Seeing correct select attribute values in different locale than default
And I add value "Banana Skin" in "French (France)"
And I add it
Then I should be notified that it has been successfully created
And it should see value "Banana Skin"
And I should see the value "Banana Skin"

View file

@ -365,9 +365,9 @@ final class ManagingProductAttributesContext implements Context
}
/**
* @Then /^it should see value "([^"]*)"/
* @Then I should see the value :value
*/
public function theSelectAttributeShouldHaveValueInLocale(string $value): void
public function iShouldSeeTheValue(string $value): void
{
Assert::true($this->updatePage->hasAttributeValue($value));
}

View file

@ -14,6 +14,7 @@ declare(strict_types=1);
namespace Sylius\Bundle\AttributeBundle\Form\Type\AttributeType\Configuration;
use Ramsey\Uuid\Uuid;
use Sylius\Component\Resource\Translation\Provider\TranslationLocaleProviderInterface;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
use Symfony\Component\Form\FormBuilderInterface;
@ -22,6 +23,15 @@ use Symfony\Component\Form\FormEvents;
class SelectAttributeChoicesCollectionType extends AbstractType
{
private ?string $defaultLocaleCode = null;
public function __construct(?TranslationLocaleProviderInterface $localeProvider = null)
{
if (null !== $localeProvider) {
$this->defaultLocaleCode = $localeProvider->getDefaultLocaleCode();
}
}
/**
* @psalm-suppress InvalidScalarArgument Some weird magic going on here, not sure about refactor
*/
@ -40,6 +50,10 @@ class SelectAttributeChoicesCollectionType extends AbstractType
continue;
}
if ($this->defaultLocaleCode !== null && !array_key_exists($this->defaultLocaleCode, $values)) {
continue;
}
$key = (string) $key;
$newKey = $this->getUniqueKey();
$fixedData[$newKey] = $this->resolveValues($values);
@ -73,6 +87,11 @@ class SelectAttributeChoicesCollectionType extends AbstractType
return Uuid::uuid1()->toString();
}
/**
* @param array<array-key, mixed|null> $values
*
* @return array<string, mixed>
*/
private function resolveValues(array $values): array
{
$fixedValues = [];