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 Jan 21, 2025
1 parent 3bc69f4 commit e9529e3
Showing 1 changed file with 22 additions and 18 deletions.
40 changes: 22 additions & 18 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)
if (
is_numeric($options[0]['value']) ||
$options[0]['value'] === $options[0]['text']
=> A::map($options, fn ($option) => [
'value' => $option['text']
]),
) {
// simple array of values
// or value=text (from Options class)
$options = A::map($options, fn ($option) => [
'value' => $option['text']
]);

} elseif ($this->isColor($options[0]['text'])) {
// @deprecated 4.0.0
// TODO: Remove in Kirby 6

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

default
=> A::map($options, fn ($option) => [
$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 = A::map($options, fn ($option) => [
'value' => $option['value'],
'text' => $option['text']
]),
};
]);
}

return $options;
}
Expand Down

0 comments on commit e9529e3

Please sign in to comment.