diff --git a/CHANGELOG-WIP.md b/CHANGELOG-WIP.md index 13b579edd06..39f61008d1e 100644 --- a/CHANGELOG-WIP.md +++ b/CHANGELOG-WIP.md @@ -1 +1,4 @@ # Release Notes for Craft CMS 5.7 (WIP) + +### Extensibility +- Added `craft\fields\data\ColorData::$label`. ([#16492](https://github.com/craftcms/cms/pull/16492)) diff --git a/src/fields/Color.php b/src/fields/Color.php index 2fb0b2214d9..8735af617bf 100644 --- a/src/fields/Color.php +++ b/src/fields/Color.php @@ -293,7 +293,15 @@ public function normalizeValue(mixed $value, ?ElementInterface $element): mixed } $value = ColorValidator::normalizeColor($value); - return new ColorData($value); + $value = new ColorData($value); + + // set the label on the value too? + $option = Arr::first($this->palette, fn(array $color) => $color['color'] === $value->getHex()); + if (isset($option['label']) && $option['label'] !== '') { + $value->label = $option['label']; + } + + return $value; } /** diff --git a/src/fields/data/ColorData.php b/src/fields/data/ColorData.php index e625daaa0ca..aec9295ccf2 100644 --- a/src/fields/data/ColorData.php +++ b/src/fields/data/ColorData.php @@ -28,6 +28,12 @@ */ class ColorData extends BaseObject implements Serializable { + /** + * @var string|null The human-facing label for the color. + * @since 5.7.0 + */ + public ?string $label = null; + /** * @var string The color’s hex value */