Skip to content

Commit 5bb8a4c

Browse files
authored
Merge pull request #16492 from craftcms/feature/color-label-property
ColorData::$label
2 parents dda6d36 + 003b167 commit 5bb8a4c

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

CHANGELOG-WIP.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
11
# Release Notes for Craft CMS 5.7 (WIP)
2+
3+
### Extensibility
4+
- Added `craft\fields\data\ColorData::$label`. ([#16492](https://github.com/craftcms/cms/pull/16492))

src/fields/Color.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,15 @@ public function normalizeValue(mixed $value, ?ElementInterface $element): mixed
293293
}
294294

295295
$value = ColorValidator::normalizeColor($value);
296-
return new ColorData($value);
296+
$value = new ColorData($value);
297+
298+
// set the label on the value too?
299+
$option = Arr::first($this->palette, fn(array $color) => $color['color'] === $value->getHex());
300+
if (isset($option['label']) && $option['label'] !== '') {
301+
$value->label = $option['label'];
302+
}
303+
304+
return $value;
297305
}
298306

299307
/**

src/fields/data/ColorData.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@
2828
*/
2929
class ColorData extends BaseObject implements Serializable
3030
{
31+
/**
32+
* @var string|null The human-facing label for the color.
33+
* @since 5.7.0
34+
*/
35+
public ?string $label = null;
36+
3137
/**
3238
* @var string The color’s hex value
3339
*/

0 commit comments

Comments
 (0)