improve color chooser and name validation (#2622)

This commit is contained in:
Kevin Papst
2021-06-25 16:35:16 +02:00
committed by GitHub
parent 0d5e0b3e80
commit 3d1fba650b
11 changed files with 77 additions and 40 deletions

View File

@@ -66,9 +66,12 @@ class ColorChoiceType extends AbstractType implements DataTransformerInterface
if ($this->isLimitedColors()) {
$choices = [];
foreach ($this->systemConfiguration->getThemeColorChoices() as $name => $color) {
$colors = $this->convertStringToColorArray($this->systemConfiguration->getThemeColorChoices());
foreach ($colors as $name => $color) {
$choices[$name] = $color;
}
$options['choices'] = $choices;
$options['search'] = false;
$options['attr']['data-renderer'] = 'color';
@@ -77,6 +80,37 @@ class ColorChoiceType extends AbstractType implements DataTransformerInterface
$resolver->setDefaults($options);
}
private function convertStringToColorArray(string $config): array
{
$config = explode(',', $config);
$colors = [];
foreach ($config as $item) {
if (empty($item)) {
continue;
}
$item = explode('|', $item);
$key = $item[0];
$value = $key;
if (\count($item) > 1) {
$value = $item[1];
}
if (empty($key)) {
$key = $value;
}
if ($value === Constants::DEFAULT_COLOR) {
continue;
}
$colors[$key] = $value;
}
return array_unique($colors);
}
/**
* {@inheritdoc}
*/