Upgrade to rc5

This commit is contained in:
Bastian Allgeier
2020-12-10 11:24:42 +01:00
parent 3fec0d7c93
commit c378376bc9
257 changed files with 13009 additions and 1846 deletions

View File

@@ -1,21 +1,38 @@
<?php
use Kirby\Exception\Exception;
use Kirby\Toolkit\I18n;
use Kirby\Toolkit\Str;
return [
'mixins' => ['datetime'],
'props' => [
/**
* Unset inherited props
*/
'placeholder' => null,
/**
* Activate/deactivate the dropdown calendar
*/
'calendar' => function (bool $calendar = true) {
return $calendar;
},
/**
* Default date when a new page/file/user gets created
*/
'default' => function ($default = null) {
'default' => function (string $default = null) {
return $default;
},
/**
* Defines a custom format that is used when the field is saved
* Custom format (dayjs tokens: `DD`, `MM`, `YYYY`) that is
* used to display the field in the Panel
*/
'format' => function (string $format = null) {
return $format;
'display' => function ($display = 'YYYY-MM-DD') {
return I18n::translate($display, $display);
},
/**
@@ -24,22 +41,52 @@ return [
'icon' => function (string $icon = 'calendar') {
return $icon;
},
/**
* Youngest date, which can be selected/saved
* Latest date, which can be selected/saved (Y-m-d)
*/
'max' => function (string $max = null) {
return $this->toDate($max);
return $this->toDatetime($max);
},
/**
* Oldest date, which can be selected/saved
* Earliest date, which can be selected/saved (Y-m-d)
*/
'min' => function (string $min = null) {
return $this->toDate($min);
return $this->toDatetime($min);
},
/**
* The placeholder is not available
* Round to the nearest: sub-options for `unit` (day) and `size` (1)
*/
'placeholder' => null,
'step' => function ($step = null) {
if ($step === null) {
return [
'size' => 1,
'unit' => 'day'
];
}
if (is_array($step) === true) {
return $step;
}
if (is_int($step) === true) {
return [
'size' => $step,
'unit' => 'day'
];
}
if (is_string($step) === true) {
return [
'size' => 1,
'unit' => $step
];
}
throw new Exception('step option has to be defined as array');
},
/**
* Pass `true` or an array of time field options to show the time selector.
*/
@@ -55,27 +102,29 @@ return [
],
'computed' => [
'default' => function () {
return $this->toDate($this->default);
return $this->toDatetime($this->default);
},
'format' => function () {
return $this->props['format'] ?? ($this->time() === false ? 'Y-m-d' : 'Y-m-d H:i');
'display' => function () {
if ($this->display) {
return Str::upper($this->display);
}
},
'value' => function () {
return $this->toDate($this->value);
},
],
'methods' => [
'toDate' => function ($value) {
if ($timestamp = timestamp($value, $this->time['step'] ?? 5)) {
return date('Y-m-d H:i:s', $timestamp);
'step' => function () {
if ($this->time !== false) {
$timeField = require __DIR__ . '/time.php';
return $timeField['props']['step']($this->time['step'] ?? null);
}
return null;
}
return $this->step;
},
'value' => function () {
return $this->toDatetime($this->value);
},
],
'save' => function ($value) {
if ($value !== null && $date = strtotime($value)) {
return date($this->format(), $date);
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 '';
@@ -86,7 +135,7 @@ return [
$min = $this->min ? strtotime($this->min) : null;
$max = $this->max ? strtotime($this->max) : null;
$value = strtotime($this->value());
$format = 'd.m.Y';
$format = $this->time === false ? 'd.m.Y' : 'd.m.Y H:i';
$errors = [];
if ($value && $min && $value < $min) {

View File

@@ -11,7 +11,6 @@ return [
'before' => null,
'default' => null,
'disabled' => null,
'help' => null,
'icon' => null,
'placeholder' => null,
'required' => null,

View File

@@ -4,6 +4,19 @@ use Kirby\Toolkit\I18n;
return [
'props' => [
/**
* Unset inherited props
*/
'after' => null,
'autofocus' => null,
'before' => null,
'default' => null,
'disabled' => null,
'icon' => null,
'placeholder' => null,
'required' => null,
'translate' => null,
/**
* Text to be displayed
*/

12
kirby/config/fields/list.php Executable file
View File

@@ -0,0 +1,12 @@
<?php
return [
'props' => [
/**
* Sets the allowed HTML formats. Available formats: `bold`, `italic`, `underline`, `strike`, `code`, `link`. Activate them all by passing `true`. Deactivate them all by passing `false`
*/
'marks' => function ($marks = true) {
return $marks;
}
]
];

View File

@@ -0,0 +1,16 @@
<?php
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 null;
},
'toISO' => function (int $time, string $format = 'Y-m-d H:i:s') {
return date($format, $time);
}
]
];

View File

@@ -30,7 +30,7 @@ return [
'template' => $template
]);
$uploads['accept'] = $file->blueprint()->accept()['mime'] ?? '*';
$uploads['accept'] = $file->blueprint()->acceptMime();
} else {
$uploads['accept'] = '*';
}

View File

@@ -99,6 +99,7 @@ return [
],
[
'pattern' => 'upload',
'method' => 'POST',
'action' => function () {
$field = $this->field();
$uploads = $field->uploads();

View File

@@ -1,24 +1,51 @@
<?php
use Kirby\Exception\Exception;
use Kirby\Toolkit\I18n;
return [
'mixins' => ['datetime'],
'props' => [
/**
* Unset inherited props
*/
'placeholder' => null,
/**
* Sets the default time when a new page/file/user is created
*/
'default' => function ($default = null) {
return $default;
},
/**
* Custom format (dayjs tokens: `HH`, `hh`, `mm`, `ss`, `a`) that is
* used to display the field in the Panel
*/
'display' => function ($display = null) {
return I18n::translate($display, $display);
},
/**
* Changes the clock icon
*/
'icon' => function (string $icon = 'clock') {
return $icon;
},
/**
* Latest time, which can be selected/saved (H:i or H:i:s)
*/
'max' => function (string $max = null) {
return $max ? $this->toDatetime(date('Y-m-d ') . $max) : null;
},
/**
* Earliest time, which can be selected/saved (H:i or H:i:s)
*/
'min' => function (string $min = null) {
return $min ? $this->toDatetime(date('Y-m-d ') . $min) : null;
},
/**
* `12` or `24` hour notation. If `12`, an AM/PM selector will be shown.
*/
@@ -26,10 +53,35 @@ return [
return $value === 24 ? 24 : 12;
},
/**
* The interval between minutes in the minutes select dropdown.
* Round to the nearest: sub-options for `unit` (minute) and `size` (5)
*/
'step' => function (int $step = 5) {
return $step;
'step' => function ($step = null) {
if ($step === null) {
return [
'size' => 5,
'unit' => 'minute'
];
}
if (is_array($step) === true) {
return $step;
}
if (is_int($step) === true) {
return [
'size' => $step,
'unit' => 'minute'
];
}
if (is_string($step) === true) {
return [
'size' => 1,
'unit' => $step
];
}
throw new Exception('step option has to be defined as array');
},
'value' => function ($value = null) {
return $value;
@@ -37,32 +89,70 @@ return [
],
'computed' => [
'default' => function () {
return $this->toTime($this->default);
return $this->toDatetime($this->default, 'H:i:s');
},
'format' => function () {
return $this->notation === 24 ? 'H:i' : 'h:i a';
},
'value' => function () {
return $this->toTime($this->value);
}
],
'methods' => [
'toTime' => function ($value) {
if ($timestamp = timestamp($value, $this->step)) {
return date('H:i', $timestamp);
'display' => function () {
if ($this->display) {
return $this->display;
}
return null;
return $this->notation === 24 ? 'HH:mm' : 'hh:mm a';
},
'value' => function () {
return $this->toDatetime($this->value, 'H:i:s');
}
],
'save' => function ($value): string {
if ($timestamp = strtotime($value)) {
return date($this->format, $timestamp);
if ($value != null && $timestamp = strtotime($value)) {
return date('H:i:s', $timestamp);
}
return '';
},
'validations' => [
'time',
'minMax' => function ($value) {
$min = $this->min ? strtotime($this->min) : null;
$max = $this->max ? strtotime($this->max) : null;
$value = strtotime($this->value());
$format = 'H:i:s';
$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.time.between',
'data' => [
'min' => date($format, $min),
'max' => date($format, $max)
]
]);
} elseif ($min) {
throw new Exception([
'key' => 'validation.time.after',
'data' => [
'time' => date($format, $min),
]
]);
} else {
throw new Exception([
'key' => 'validation.time.before',
'data' => [
'time' => date($format, $max),
]
]);
}
}
return true;
},
]
];

View File

@@ -59,9 +59,7 @@ return [
'boolean',
'required' => function ($value) {
if ($this->isRequired() && ($value === false || $this->isEmpty($value))) {
throw new InvalidArgumentException([
'key' => 'form.field.required'
]);
throw new InvalidArgumentException(I18n::translate('field.required'));
}
},
]

20
kirby/config/fields/writer.php Executable file
View File

@@ -0,0 +1,20 @@
<?php
return [
'props' => [
/**
* Enables inline mode, which will not wrap new lines in paragraphs and creates hard breaks instead.
*
* @param bool $inline
*/
'inline' => function (bool $inline = false) {
return $inline;
},
/**
* Sets the allowed HTML formats. Available formats: `bold`, `italic`, `underline`, `strike`, `code`, `link`. Activate them all by passing `true`. Deactivate them all by passing `false`
*/
'marks' => function ($marks = true) {
return $marks;
}
]
];