Upgrade to 3.5
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
|
||||
use Kirby\Exception\Exception;
|
||||
use Kirby\Form\Field;
|
||||
use Kirby\Toolkit\I18n;
|
||||
use Kirby\Toolkit\Str;
|
||||
|
||||
@@ -59,32 +60,28 @@ return [
|
||||
* 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 [
|
||||
'size' => 1,
|
||||
'unit' => 'day'
|
||||
];
|
||||
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 [
|
||||
'size' => $step,
|
||||
'unit' => 'day'
|
||||
];
|
||||
return array_merge($default, ['size' => $step]);
|
||||
}
|
||||
|
||||
if (is_string($step) === true) {
|
||||
return [
|
||||
'size' => 1,
|
||||
'unit' => $step
|
||||
];
|
||||
return array_merge($default, ['unit' => strtolower($step)]);
|
||||
}
|
||||
|
||||
throw new Exception('step option has to be defined as array');
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -109,25 +106,30 @@ return [
|
||||
return Str::upper($this->display);
|
||||
}
|
||||
},
|
||||
'step' => function () {
|
||||
if ($this->time !== false) {
|
||||
$timeField = require __DIR__ . '/time.php';
|
||||
return $timeField['props']['step']($this->time['step'] ?? null);
|
||||
'time' => function () {
|
||||
if ($this->time === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->step;
|
||||
$props = is_array($this->time) ? $this->time : [];
|
||||
$props['model'] = $this->model();
|
||||
$field = new Field('time', $props);
|
||||
return $field->toArray();
|
||||
},
|
||||
'step' => function () {
|
||||
if ($this->time === false) {
|
||||
return $this->step;
|
||||
}
|
||||
|
||||
return $this->time['step'];
|
||||
},
|
||||
'value' => function () {
|
||||
return $this->toDatetime($this->value);
|
||||
},
|
||||
],
|
||||
'save' => function ($value) {
|
||||
if ($value !== null && $timestamp = timestamp($value)) {
|
||||
$format = $this->time === false ? 'Y-m-d' : 'Y-m-d H:i:s';
|
||||
return $this->toISO($timestamp, $format);
|
||||
}
|
||||
|
||||
return '';
|
||||
$format = $this->time === false ? 'Y-m-d' : 'Y-m-d H:i:s';
|
||||
return $this->toContent($value, $format);
|
||||
},
|
||||
'validations' => [
|
||||
'date',
|
||||
|
@@ -23,6 +23,13 @@ return [
|
||||
'text' => function ($value = null) {
|
||||
return I18n::translate($value, $value);
|
||||
},
|
||||
|
||||
/**
|
||||
* Change the design of the info box
|
||||
*/
|
||||
'theme' => function (string $theme = null) {
|
||||
return $theme;
|
||||
}
|
||||
],
|
||||
'computed' => [
|
||||
'text' => function () {
|
||||
|
@@ -4,13 +4,17 @@ return [
|
||||
'methods' => [
|
||||
'toDatetime' => function ($value, string $format = 'Y-m-d H:i:s') {
|
||||
if ($timestamp = timestamp($value, $this->step)) {
|
||||
return $this->toISO($timestamp, $format);
|
||||
return date($format, $timestamp);
|
||||
}
|
||||
|
||||
return null;
|
||||
},
|
||||
'toISO' => function (int $time, string $format = 'Y-m-d H:i:s') {
|
||||
return date($format, $time);
|
||||
'toContent' => function ($value, string $format = 'Y-m-d H:i:s') {
|
||||
if ($value !== null && $timestamp = strtotime($value)) {
|
||||
return date($format, $timestamp);
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
]
|
||||
];
|
||||
|
@@ -48,6 +48,7 @@ return [
|
||||
|
||||
/**
|
||||
* `12` or `24` hour notation. If `12`, an AM/PM selector will be shown.
|
||||
* If `display` is defined, that option will take priority.
|
||||
*/
|
||||
'notation' => function (int $value = 24) {
|
||||
return $value === 24 ? 24 : 12;
|
||||
@@ -56,32 +57,28 @@ return [
|
||||
* Round to the nearest: sub-options for `unit` (minute) and `size` (5)
|
||||
*/
|
||||
'step' => function ($step = null) {
|
||||
$default = [
|
||||
'size' => 5,
|
||||
'unit' => 'minute'
|
||||
];
|
||||
|
||||
if ($step === null) {
|
||||
return [
|
||||
'size' => 5,
|
||||
'unit' => 'minute'
|
||||
];
|
||||
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 [
|
||||
'size' => $step,
|
||||
'unit' => 'minute'
|
||||
];
|
||||
return array_merge($default, ['size' => $step]);
|
||||
}
|
||||
|
||||
if (is_string($step) === true) {
|
||||
return [
|
||||
'size' => 1,
|
||||
'unit' => $step
|
||||
];
|
||||
return array_merge($default, ['unit' => strtolower($step)]);
|
||||
}
|
||||
|
||||
throw new Exception('step option has to be defined as array');
|
||||
},
|
||||
'value' => function ($value = null) {
|
||||
return $value;
|
||||
@@ -96,18 +93,14 @@ return [
|
||||
return $this->display;
|
||||
}
|
||||
|
||||
return $this->notation === 24 ? 'HH:mm' : 'hh:mm a';
|
||||
return $this->notation === 24 ? 'HH:mm' : 'h:mm a';
|
||||
},
|
||||
'value' => function () {
|
||||
return $this->toDatetime($this->value, 'H:i:s');
|
||||
}
|
||||
],
|
||||
'save' => function ($value): string {
|
||||
if ($value != null && $timestamp = strtotime($value)) {
|
||||
return date('H:i:s', $timestamp);
|
||||
}
|
||||
|
||||
return '';
|
||||
return $this->toContent($value, 'H:i:s');
|
||||
},
|
||||
'validations' => [
|
||||
'time',
|
||||
|
@@ -709,10 +709,6 @@ function svg($file)
|
||||
if (file_exists($file) === false) {
|
||||
$root = App::instance()->root();
|
||||
$file = realpath($root . '/' . $file);
|
||||
|
||||
if (file_exists($file) === false) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return F::read($file);
|
||||
@@ -762,10 +758,11 @@ function timestamp(string $date = null, $step = null): ?string
|
||||
return $date;
|
||||
}
|
||||
|
||||
// fallback for pre-3.5.0 usage
|
||||
if (is_int($step) === true) {
|
||||
$step = [
|
||||
'unit' => 'minute',
|
||||
'size' => 1
|
||||
'size' => $step
|
||||
];
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user