Skip to content

Commit

Permalink
Color field: warning for deprecated notation
Browse files Browse the repository at this point in the history
  • Loading branch information
distantnative committed Dec 7, 2024
1 parent 4b8e371 commit ae392f4
Showing 1 changed file with 25 additions and 21 deletions.
46 changes: 25 additions & 21 deletions config/fields/color.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

use Kirby\Cms\Helpers;
use Kirby\Exception\InvalidArgumentException;
use Kirby\Field\FieldOptions;
use Kirby\Toolkit\A;
Expand Down Expand Up @@ -73,30 +74,33 @@
return [];
}

$options = match (true) {
// simple array of values
// or value=text (from Options class)
is_numeric($options[0]['value']) ||
$options[0]['value'] === $options[0]['text']
=> A::map($options, fn ($option) => [
'value' => $option['text']
]),
// @deprecated 4.0.0
// TODO: Remove in Kirby 6
if ($this->isColor($options[0]['text'])) {
Helpers::deprecated('Color field: the text => value notation for options has been deprecated and will be removed in Kirby 6. Please rewrite your options as value => text.');

$options = A::map($options, fn ($option) => [
'value' => $option['text'],
// ensure that any HTML in the new text is escaped
'text' => Escape::html($option['value'])
]);
} else {
$options = match (true) {
// simple array of values
// or value=text (from Options class)
is_numeric($options[0]['value']) ||
$options[0]['value'] === $options[0]['text']
=> A::map($options, fn ($option) => [
'value' => $option['text']
]),

// deprecated: name => value, flipping
// TODO: start throwing in warning in v5
$this->isColor($options[0]['text'])
default
=> A::map($options, fn ($option) => [
'value' => $option['text'],
// ensure that any HTML in the new text is escaped
'text' => Escape::html($option['value'])
'value' => $option['value'],
'text' => $option['text']
]),

default
=> A::map($options, fn ($option) => [
'value' => $option['value'],
'text' => $option['text']
]),
};
};
}

return $options;
}
Expand Down

0 comments on commit ae392f4

Please sign in to comment.