Update Kirby and Composer dependencies
This commit is contained in:
parent
f5d3ea5e84
commit
ec74d78ba9
382 changed files with 25077 additions and 4955 deletions
|
@ -2,6 +2,7 @@
|
|||
|
||||
use Kirby\Exception\Exception;
|
||||
use Kirby\Form\Field;
|
||||
use Kirby\Toolkit\Date;
|
||||
use Kirby\Toolkit\I18n;
|
||||
use Kirby\Toolkit\Str;
|
||||
|
||||
|
@ -20,12 +21,11 @@ return [
|
|||
return $calendar;
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* Default date when a new page/file/user gets created
|
||||
*/
|
||||
'default' => function (string $default = null) {
|
||||
return $default;
|
||||
'default' => function (string $default = null): string {
|
||||
return $this->toDatetime($default) ?? '';
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -46,42 +46,21 @@ return [
|
|||
/**
|
||||
* Latest date, which can be selected/saved (Y-m-d)
|
||||
*/
|
||||
'max' => function (string $max = null) {
|
||||
return $this->toDatetime($max);
|
||||
'max' => function (string $max = null): ?string {
|
||||
return Date::optional($max);
|
||||
},
|
||||
/**
|
||||
* Earliest date, which can be selected/saved (Y-m-d)
|
||||
*/
|
||||
'min' => function (string $min = null) {
|
||||
return $this->toDatetime($min);
|
||||
'min' => function (string $min = null): ?string {
|
||||
return Date::optional($min);
|
||||
},
|
||||
|
||||
/**
|
||||
* Round to the nearest: sub-options for `unit` (day) and `size` (1)
|
||||
*/
|
||||
'step' => function ($step = null) {
|
||||
$default = [
|
||||
'size' => 1,
|
||||
'unit' => 'day'
|
||||
];
|
||||
|
||||
if ($step === null) {
|
||||
return $default;
|
||||
}
|
||||
|
||||
if (is_array($step) === true) {
|
||||
$step = array_merge($default, $step);
|
||||
$step['unit'] = strtolower($step['unit']);
|
||||
return $step;
|
||||
}
|
||||
|
||||
if (is_int($step) === true) {
|
||||
return array_merge($default, ['size' => $step]);
|
||||
}
|
||||
|
||||
if (is_string($step) === true) {
|
||||
return array_merge($default, ['unit' => strtolower($step)]);
|
||||
}
|
||||
return $step;
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -95,12 +74,9 @@ return [
|
|||
*/
|
||||
'value' => function ($value = null) {
|
||||
return $value;
|
||||
},
|
||||
}
|
||||
],
|
||||
'computed' => [
|
||||
'default' => function () {
|
||||
return $this->toDatetime($this->default);
|
||||
},
|
||||
'display' => function () {
|
||||
if ($this->display) {
|
||||
return Str::upper($this->display);
|
||||
|
@ -120,57 +96,56 @@ return [
|
|||
return $field->toArray();
|
||||
},
|
||||
'step' => function () {
|
||||
if ($this->time === false) {
|
||||
return $this->step;
|
||||
if ($this->time === false || empty($this->time['step']) === true) {
|
||||
return Date::stepConfig($this->step, [
|
||||
'size' => 1,
|
||||
'unit' => 'day'
|
||||
]);
|
||||
}
|
||||
|
||||
return $this->time['step'];
|
||||
return Date::stepConfig($this->time['step'], [
|
||||
'size' => 5,
|
||||
'unit' => 'minute'
|
||||
]);
|
||||
},
|
||||
'value' => function () {
|
||||
return $this->toDatetime($this->value);
|
||||
'value' => function (): string {
|
||||
return $this->toDatetime($this->value) ?? '';
|
||||
},
|
||||
],
|
||||
'validations' => [
|
||||
'date',
|
||||
'minMax' => function ($value) {
|
||||
$min = $this->min ? strtotime($this->min) : null;
|
||||
$max = $this->max ? strtotime($this->max) : null;
|
||||
$value = strtotime($this->value());
|
||||
if (!$value = Date::optional($value)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$min = Date::optional($this->min);
|
||||
$max = Date::optional($this->max);
|
||||
|
||||
$format = $this->time === false ? 'd.m.Y' : 'd.m.Y H:i';
|
||||
$errors = [];
|
||||
|
||||
if ($value && $min && $value < $min) {
|
||||
$errors['min'] = $min;
|
||||
}
|
||||
|
||||
if ($value && $max && $value > $max) {
|
||||
$errors['max'] = $max;
|
||||
}
|
||||
|
||||
if (empty($errors) === false) {
|
||||
if ($min && $max) {
|
||||
throw new Exception([
|
||||
'key' => 'validation.date.between',
|
||||
'data' => [
|
||||
'min' => date($format, $min),
|
||||
'max' => date($format, $max)
|
||||
]
|
||||
]);
|
||||
} elseif ($min) {
|
||||
throw new Exception([
|
||||
'key' => 'validation.date.after',
|
||||
'data' => [
|
||||
'date' => date($format, $min),
|
||||
]
|
||||
]);
|
||||
} else {
|
||||
throw new Exception([
|
||||
'key' => 'validation.date.before',
|
||||
'data' => [
|
||||
'date' => date($format, $max),
|
||||
]
|
||||
]);
|
||||
}
|
||||
if ($min && $max && $value->isBetween($min, $max) === false) {
|
||||
throw new Exception([
|
||||
'key' => 'validation.date.between',
|
||||
'data' => [
|
||||
'min' => $min->format($format),
|
||||
'max' => $min->format($format)
|
||||
]
|
||||
]);
|
||||
} elseif ($min && $value->isMin($min) === false) {
|
||||
throw new Exception([
|
||||
'key' => 'validation.date.after',
|
||||
'data' => [
|
||||
'date' => $min->format($format),
|
||||
]
|
||||
]);
|
||||
} elseif ($max && $value->isMax($max) === false) {
|
||||
throw new Exception([
|
||||
'key' => 'validation.date.before',
|
||||
'data' => [
|
||||
'date' => $max->format($format),
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue