Merge pull request #8158 from pamil/attribute-select

Allow for select attribute values to contain non-latin characters
This commit is contained in:
Paweł Jędrzejewski 2017-06-20 12:06:46 +02:00 committed by GitHub
commit 8700b3eb6f
2 changed files with 16 additions and 2 deletions

View file

@ -13,7 +13,7 @@ Feature: Adding a new select product attribute
Given I want to create a new select product attribute
When I specify its code as "mug_material"
And I name it "Mug material" in "English (United States)"
And I add material "Banana Skin"
And I add material "-100% Banana Skin"
And I add it
Then I should be notified that it has been successfully created
And the select attribute "Mug material" should appear in the store

View file

@ -34,7 +34,7 @@ class SelectAttributeChoicesCollectionType extends AbstractType
if (null !== $data) {
$fixedArray = [];
foreach ($data as $key => $value) {
$newKey = strtolower(str_replace(' ', '_', $value));
$newKey = $this->getValidFormKey($value);
$fixedArray[$newKey] = $value;
if ($form->offsetExists($key)) {
@ -63,4 +63,18 @@ class SelectAttributeChoicesCollectionType extends AbstractType
{
return 'sylius_select_attribute_choices_collection';
}
/**
* @param string $value
*
* @return string
*/
private function getValidFormKey($value)
{
$newKey = strtolower(str_replace(' ', '_', $value));
$newKey = preg_replace('/[^a-zA-Z0-9\-_:]/', '', $newKey);
$newKey = preg_replace('/^[^a-zA-Z0-9_]++/', '', $newKey);
return $newKey;
}
}