Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonkelly committed Dec 1, 2024
1 parent 4c3a8cb commit 6082369
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/fields/Color.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ public function __construct($config = [])
{
// presets => palette
if (array_key_exists('presets', $config) || array_key_exists('defaultColor', $config)) {
$default = ArrayHelper::remove($config, 'defaultColor');
$defaultColor = ArrayHelper::remove($config, 'defaultColor');
$config['palette'] = array_map(fn(string $color) => [
'color' => $color,
'label' => null,
'default' => ($color === $default),
'default' => ($color === $defaultColor),
], ArrayHelper::remove($config, 'presets') ?? []);
}

Expand Down Expand Up @@ -260,8 +260,11 @@ public function normalizeValue(mixed $value, ?ElementInterface $element): mixed
}

// If this is a new entry, look for any default options
if ($value === null && $this->isFresh($element) && $this->defaultColor) {
$value = $this->defaultColor;
if ($value === null && $this->isFresh($element)) {
$defaultColor = $this->getDefaultColor();
if ($defaultColor) {
$value = $defaultColor;
}
}

$value = trim($value);
Expand Down

0 comments on commit 6082369

Please sign in to comment.