2022-06-17 17:51:59 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
use Kirby\Toolkit\Str;
|
|
|
|
|
|
|
|
return [
|
2022-08-31 15:02:43 +02:00
|
|
|
'props' => [
|
|
|
|
/**
|
|
|
|
* Default number that will be saved when a new page/user/file is created
|
|
|
|
*/
|
|
|
|
'default' => function ($default = null) {
|
2024-12-20 12:37:52 +01:00
|
|
|
return $this->toNumber($default) ?? '';
|
2022-08-31 15:02:43 +02:00
|
|
|
},
|
|
|
|
/**
|
|
|
|
* The lowest allowed number
|
|
|
|
*/
|
2025-04-21 18:57:21 +02:00
|
|
|
'min' => function (float|null $min = null) {
|
2022-08-31 15:02:43 +02:00
|
|
|
return $min;
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* The highest allowed number
|
|
|
|
*/
|
2025-04-21 18:57:21 +02:00
|
|
|
'max' => function (float|null $max = null) {
|
2022-08-31 15:02:43 +02:00
|
|
|
return $max;
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* Allowed incremental steps between numbers (i.e `0.5`)
|
2025-07-04 15:08:52 +02:00
|
|
|
* Use `any` to allow any decimal value.
|
2022-08-31 15:02:43 +02:00
|
|
|
*/
|
2025-07-04 15:08:52 +02:00
|
|
|
'step' => function ($step = null): float|string {
|
|
|
|
return match ($step) {
|
|
|
|
'any' => 'any',
|
|
|
|
default => $this->toNumber($step) ?? ''
|
|
|
|
};
|
2022-08-31 15:02:43 +02:00
|
|
|
},
|
|
|
|
'value' => function ($value = null) {
|
2024-12-20 12:37:52 +01:00
|
|
|
return $this->toNumber($value) ?? '';
|
2022-08-31 15:02:43 +02:00
|
|
|
}
|
|
|
|
],
|
|
|
|
'methods' => [
|
2025-07-04 15:08:52 +02:00
|
|
|
'toNumber' => function ($value): float|null {
|
2025-07-11 14:41:34 +02:00
|
|
|
if ($this->isEmptyValue($value) === true) {
|
2022-08-31 15:02:43 +02:00
|
|
|
return null;
|
|
|
|
}
|
2022-06-17 17:51:59 +02:00
|
|
|
|
2022-08-31 15:02:43 +02:00
|
|
|
return is_float($value) === true ? $value : (float)Str::float($value);
|
|
|
|
}
|
|
|
|
],
|
|
|
|
'validations' => [
|
|
|
|
'min',
|
|
|
|
'max'
|
|
|
|
]
|
2022-06-17 17:51:59 +02:00
|
|
|
];
|