improve color chooser and name validation (#2622)
This commit is contained in:
@@ -17,6 +17,10 @@ trait StringAccessibleConfigTrait
|
||||
* @var array
|
||||
*/
|
||||
protected $settings;
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $original;
|
||||
/**
|
||||
* @var ConfigLoaderInterface
|
||||
*/
|
||||
@@ -29,7 +33,7 @@ trait StringAccessibleConfigTrait
|
||||
public function __construct(ConfigLoaderInterface $repository, array $settings)
|
||||
{
|
||||
$this->repository = $repository;
|
||||
$this->settings = $settings;
|
||||
$this->original = $this->settings = $settings;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -80,6 +84,17 @@ trait StringAccessibleConfigTrait
|
||||
*/
|
||||
abstract protected function getPrefix(): string;
|
||||
|
||||
/**
|
||||
* @param string $key
|
||||
* @return mixed
|
||||
*/
|
||||
public function default(string $key)
|
||||
{
|
||||
$key = $this->prepareSearchKey($key);
|
||||
|
||||
return $this->get($key, $this->original);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $key
|
||||
* @return mixed
|
||||
|
||||
@@ -367,32 +367,13 @@ class SystemConfiguration implements SystemBundleConfiguration
|
||||
return (int) $this->find('theme.autocomplete_chars');
|
||||
}
|
||||
|
||||
public function getThemeColorChoices(): ?array
|
||||
public function getThemeColorChoices(): ?string
|
||||
{
|
||||
$config = $this->find('theme.color_choices');
|
||||
if (empty($config)) {
|
||||
return null;
|
||||
}
|
||||
$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;
|
||||
}
|
||||
$colors[$key] = $value;
|
||||
if (!empty($config)) {
|
||||
return $config;
|
||||
}
|
||||
|
||||
return array_unique($colors);
|
||||
return $this->default('theme.color_choices');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user