julienmonnerie/kirby/config/fields/select.php

39 lines
794 B
PHP
Raw Normal View History

2022-06-17 17:51:59 +02:00
<?php
2023-04-14 16:34:06 +02:00
use Kirby\Field\FieldOptions;
use Kirby\Toolkit\I18n;
2023-04-14 16:34:06 +02:00
2022-06-17 17:51:59 +02:00
return [
2022-08-31 15:02:43 +02:00
'extends' => 'radio',
'props' => [
/**
* Unset inherited props
*/
'columns' => null,
2022-06-17 17:51:59 +02:00
2022-08-31 15:02:43 +02:00
/**
* Custom icon to replace the arrow down.
*/
2025-04-21 18:57:21 +02:00
'icon' => function (string|null $icon = null) {
2022-08-31 15:02:43 +02:00
return $icon;
},
/**
2025-07-11 14:41:34 +02:00
* Text shown when no option is selected yet
2022-08-31 15:02:43 +02:00
*/
'placeholder' => function (string|array $placeholder = '—') {
return I18n::translate($placeholder, $placeholder);
2022-08-31 15:02:43 +02:00
},
2023-04-14 16:34:06 +02:00
],
'methods' => [
'getOptions' => function () {
$props = FieldOptions::polyfill($this->props);
// disable safe mode as the select field does not
// render HTML for the option text
$options = FieldOptions::factory($props['options'], false);
return $options->render($this->model());
}
2022-08-31 15:02:43 +02:00
]
2022-06-17 17:51:59 +02:00
];