Update Composer packages
This commit is contained in:
parent
0320235f6c
commit
a8b68fb61b
378 changed files with 28466 additions and 28852 deletions
|
@ -46,13 +46,13 @@ return [
|
|||
/**
|
||||
* Latest date, which can be selected/saved (Y-m-d)
|
||||
*/
|
||||
'max' => function (string $max = null): ?string {
|
||||
'max' => function (string $max = null): string|null {
|
||||
return Date::optional($max);
|
||||
},
|
||||
/**
|
||||
* Earliest date, which can be selected/saved (Y-m-d)
|
||||
*/
|
||||
'min' => function (string $min = null): ?string {
|
||||
'min' => function (string $min = null): string|null {
|
||||
return Date::optional($min);
|
||||
},
|
||||
|
||||
|
|
|
@ -34,7 +34,10 @@ return [
|
|||
],
|
||||
'computed' => [
|
||||
'parentModel' => function () {
|
||||
if (is_string($this->parent) === true && $model = $this->model()->query($this->parent, 'Kirby\Cms\Model')) {
|
||||
if (
|
||||
is_string($this->parent) === true &&
|
||||
$model = $this->model()->query($this->parent, 'Kirby\Cms\Model')
|
||||
) {
|
||||
return $model;
|
||||
}
|
||||
|
||||
|
@ -68,10 +71,13 @@ return [
|
|||
|
||||
foreach (Data::decode($value, 'yaml') as $id) {
|
||||
if (is_array($id) === true) {
|
||||
$id = $id['id'] ?? null;
|
||||
$id = $id['uuid'] ?? $id['id'] ?? null;
|
||||
}
|
||||
|
||||
if ($id !== null && ($file = $this->kirby()->file($id, $this->model()))) {
|
||||
if (
|
||||
$id !== null &&
|
||||
($file = $this->kirby()->file($id, $this->model()))
|
||||
) {
|
||||
$files[] = $this->fileResponse($file);
|
||||
}
|
||||
}
|
||||
|
@ -122,7 +128,7 @@ return [
|
|||
];
|
||||
},
|
||||
'save' => function ($value = null) {
|
||||
return A::pluck($value, 'uuid');
|
||||
return A::pluck($value, $this->store);
|
||||
},
|
||||
'validations' => [
|
||||
'max',
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
use Kirby\Form\Options;
|
||||
use Kirby\Field\FieldOptions;
|
||||
|
||||
return [
|
||||
'props' => [
|
||||
|
@ -30,19 +30,18 @@ return [
|
|||
],
|
||||
'methods' => [
|
||||
'getOptions' => function () {
|
||||
return Options::factory(
|
||||
$this->options(),
|
||||
$this->props,
|
||||
$this->model()
|
||||
);
|
||||
$props = FieldOptions::polyfill($this->props);
|
||||
$options = FieldOptions::factory($props['options']);
|
||||
return $options->render($this->model());
|
||||
},
|
||||
'sanitizeOption' => function ($option) {
|
||||
$allowed = array_column($this->options(), 'value');
|
||||
return in_array($option, $allowed, true) === true ? $option : null;
|
||||
'sanitizeOption' => function ($value) {
|
||||
$options = array_column($this->options(), 'value');
|
||||
return in_array($value, $options, true) === true ? $value : null;
|
||||
},
|
||||
'sanitizeOptions' => function ($options) {
|
||||
$allowed = array_column($this->options(), 'value');
|
||||
return array_intersect($options, $allowed);
|
||||
'sanitizeOptions' => function ($values) {
|
||||
$options = array_column($this->options(), 'value');
|
||||
$options = array_intersect($values, $options);
|
||||
return array_values($options);
|
||||
},
|
||||
]
|
||||
];
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
<?php
|
||||
|
||||
use Kirby\Toolkit\I18n;
|
||||
use Kirby\Toolkit\Str;
|
||||
|
||||
return [
|
||||
'props' => [
|
||||
|
@ -67,12 +68,21 @@ return [
|
|||
return $search;
|
||||
},
|
||||
|
||||
/**
|
||||
* Whether to store UUID or ID in the
|
||||
* content file of the model
|
||||
*
|
||||
* @param string $store 'uuid'|'id'
|
||||
*/
|
||||
'store' => function (string $store = 'uuid') {
|
||||
return Str::lower($store);
|
||||
},
|
||||
|
||||
/**
|
||||
* Main text for each item
|
||||
*/
|
||||
'text' => function (string $text = null) {
|
||||
return $text;
|
||||
},
|
||||
|
||||
],
|
||||
];
|
||||
|
|
|
@ -51,7 +51,7 @@ return [
|
|||
$parent = $this->model();
|
||||
}
|
||||
|
||||
if (is_a($parent, 'Kirby\Cms\File') === true) {
|
||||
if ($parent instanceof File) {
|
||||
$parent = $parent->parent();
|
||||
}
|
||||
|
||||
|
@ -62,7 +62,7 @@ return [
|
|||
'filename' => $filename,
|
||||
]);
|
||||
|
||||
if (is_a($file, 'Kirby\Cms\File') === false) {
|
||||
if ($file instanceof File === false) {
|
||||
throw new Exception('The file could not be uploaded');
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
use Kirby\Toolkit\Str;
|
||||
|
||||
return [
|
||||
'extends' => 'tags',
|
||||
'props' => [
|
||||
|
@ -28,5 +30,18 @@ return [
|
|||
'sort' => function (bool $sort = false) {
|
||||
return $sort;
|
||||
},
|
||||
]
|
||||
],
|
||||
'methods' => [
|
||||
'toValues' => function ($value) {
|
||||
if (is_null($value) === true) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (is_array($value) === false) {
|
||||
$value = Str::split($value, $this->separator());
|
||||
}
|
||||
|
||||
return $this->sanitizeOptions($value);
|
||||
}
|
||||
],
|
||||
];
|
||||
|
|
104
kirby/config/fields/object.php
Normal file
104
kirby/config/fields/object.php
Normal file
|
@ -0,0 +1,104 @@
|
|||
<?php
|
||||
|
||||
use Kirby\Data\Data;
|
||||
use Kirby\Exception\InvalidArgumentException;
|
||||
use Kirby\Form\Form;
|
||||
use Kirby\Toolkit\I18n;
|
||||
|
||||
return [
|
||||
'props' => [
|
||||
/**
|
||||
* Unset inherited props
|
||||
*/
|
||||
'after' => null,
|
||||
'before' => null,
|
||||
'autofocus' => null,
|
||||
'icon' => null,
|
||||
'placeholder' => null,
|
||||
|
||||
/**
|
||||
* Set the default values for the object
|
||||
*/
|
||||
'default' => function ($default = null) {
|
||||
return $default;
|
||||
},
|
||||
|
||||
/**
|
||||
* The placeholder text if no information has been added yet
|
||||
*/
|
||||
'empty' => function ($empty = null) {
|
||||
return I18n::translate($empty, $empty);
|
||||
},
|
||||
|
||||
/**
|
||||
* Fields setup for the object form. Works just like fields in regular forms.
|
||||
*/
|
||||
'fields' => function (array $fields = []) {
|
||||
return $fields;
|
||||
}
|
||||
],
|
||||
'computed' => [
|
||||
'default' => function () {
|
||||
if (empty($this->default) === true) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return $this->form($this->default)->values();
|
||||
},
|
||||
'fields' => function () {
|
||||
if (empty($this->fields) === true) {
|
||||
throw new Exception('Please provide some fields for the object');
|
||||
}
|
||||
|
||||
return $this->form()->fields()->toArray();
|
||||
},
|
||||
'value' => function () {
|
||||
$data = Data::decode($this->value, 'yaml');
|
||||
|
||||
if (empty($data) === true) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return $this->form($data)->values();
|
||||
}
|
||||
],
|
||||
'methods' => [
|
||||
'form' => function (array $values = []) {
|
||||
return new Form([
|
||||
'fields' => $this->attrs['fields'],
|
||||
'values' => $values,
|
||||
'model' => $this->model
|
||||
]);
|
||||
},
|
||||
],
|
||||
'save' => function ($value) {
|
||||
if (empty($value) === true) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return $this->form($value)->content();
|
||||
},
|
||||
'validations' => [
|
||||
'object' => function ($value) {
|
||||
if (empty($value) === true) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$errors = $this->form($value)->errors();
|
||||
|
||||
if (empty($errors) === false) {
|
||||
// use the first error for details
|
||||
$name = array_key_first($errors);
|
||||
$error = $errors[$name];
|
||||
|
||||
throw new InvalidArgumentException([
|
||||
'key' => 'object.validation',
|
||||
'data' => [
|
||||
'label' => $error['label'] ?? $name,
|
||||
'message' => implode("\n", $error['message'])
|
||||
]
|
||||
]);
|
||||
}
|
||||
}
|
||||
]
|
||||
];
|
|
@ -67,7 +67,7 @@ return [
|
|||
|
||||
foreach (Data::decode($value, 'yaml') as $id) {
|
||||
if (is_array($id) === true) {
|
||||
$id = $id['id'] ?? null;
|
||||
$id = $id['uuid'] ?? $id['id'] ?? null;
|
||||
}
|
||||
|
||||
if ($id !== null && ($page = $kirby->page($id))) {
|
||||
|
@ -102,7 +102,7 @@ return [
|
|||
];
|
||||
},
|
||||
'save' => function ($value = null) {
|
||||
return A::pluck($value, 'id');
|
||||
return A::pluck($value, $this->store);
|
||||
},
|
||||
'validations' => [
|
||||
'max',
|
||||
|
|
|
@ -108,7 +108,7 @@ return [
|
|||
$columns = [];
|
||||
$mobile = 0;
|
||||
|
||||
if (empty($this->columns)) {
|
||||
if (empty($this->columns) === true) {
|
||||
foreach ($this->fields as $field) {
|
||||
// Skip hidden and unsaveable fields
|
||||
// They should never be included as column
|
||||
|
@ -129,7 +129,10 @@ return [
|
|||
|
||||
$field = $this->fields[$columnName] ?? null;
|
||||
|
||||
if (empty($field) === true || $field['saveable'] === false) {
|
||||
if (
|
||||
empty($field) === true ||
|
||||
$field['saveable'] === false
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -137,10 +140,10 @@ return [
|
|||
$mobile++;
|
||||
}
|
||||
|
||||
$columns[$columnName] = array_merge($columnProps, [
|
||||
$columns[$columnName] = array_merge([
|
||||
'type' => $field['type'],
|
||||
'label' => $field['label'] ?? $field['name']
|
||||
]);
|
||||
], $columnProps);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ return [
|
|||
* Set to `list` to display each tag with 100% width,
|
||||
* otherwise the tags are displayed inline
|
||||
*/
|
||||
'layout' => function (?string $layout = null) {
|
||||
'layout' => function (string|null $layout = null) {
|
||||
return $layout;
|
||||
},
|
||||
/**
|
||||
|
@ -55,43 +55,32 @@ return [
|
|||
],
|
||||
'computed' => [
|
||||
'default' => function (): array {
|
||||
return $this->toTags($this->default);
|
||||
return $this->toValues($this->default);
|
||||
},
|
||||
'value' => function (): array {
|
||||
return $this->toTags($this->value);
|
||||
return $this->toValues($this->value);
|
||||
}
|
||||
],
|
||||
'methods' => [
|
||||
'toTags' => function ($value) {
|
||||
'toValues' => function ($value) {
|
||||
if (is_null($value) === true) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$options = $this->options();
|
||||
if (is_array($value) === false) {
|
||||
$value = Str::split($value, $this->separator());
|
||||
}
|
||||
|
||||
// transform into value-text objects
|
||||
return array_map(function ($option) use ($options) {
|
||||
// already a valid object
|
||||
if (is_array($option) === true && isset($option['value'], $option['text']) === true) {
|
||||
return $option;
|
||||
}
|
||||
if ($this->accept === 'options') {
|
||||
$value = $this->sanitizeOptions($value);
|
||||
}
|
||||
|
||||
$index = array_search($option, array_column($options, 'value'));
|
||||
|
||||
if ($index !== false) {
|
||||
return $options[$index];
|
||||
}
|
||||
|
||||
return [
|
||||
'value' => $option,
|
||||
'text' => $option,
|
||||
];
|
||||
}, Str::split($value, $this->separator()));
|
||||
return $value;
|
||||
}
|
||||
],
|
||||
'save' => function (array $value = null): string {
|
||||
return A::join(
|
||||
A::pluck($value, 'value'),
|
||||
$value,
|
||||
$this->separator() . ' '
|
||||
);
|
||||
},
|
||||
|
|
|
@ -15,7 +15,7 @@ return [
|
|||
/**
|
||||
* Sets the default time when a new page/file/user is created
|
||||
*/
|
||||
'default' => function ($default = null): ?string {
|
||||
'default' => function ($default = null): string|null {
|
||||
return $default;
|
||||
},
|
||||
|
||||
|
@ -36,13 +36,13 @@ return [
|
|||
/**
|
||||
* Latest time, which can be selected/saved (H:i or H:i:s)
|
||||
*/
|
||||
'max' => function (string $max = null): ?string {
|
||||
'max' => function (string $max = null): string|null {
|
||||
return Date::optional($max);
|
||||
},
|
||||
/**
|
||||
* Earliest time, which can be selected/saved (H:i or H:i:s)
|
||||
*/
|
||||
'min' => function (string $min = null): ?string {
|
||||
'min' => function (string $min = null): string|null {
|
||||
return Date::optional($min);
|
||||
},
|
||||
|
||||
|
@ -62,7 +62,7 @@ return [
|
|||
'unit' => 'minute',
|
||||
]);
|
||||
},
|
||||
'value' => function ($value = null): ?string {
|
||||
'value' => function ($value = null): string|null {
|
||||
return $value;
|
||||
}
|
||||
],
|
||||
|
@ -80,7 +80,7 @@ return [
|
|||
'format' => function () {
|
||||
return $this->props['format'] ?? 'H:i:s';
|
||||
},
|
||||
'value' => function (): ?string {
|
||||
'value' => function (): string|null {
|
||||
return $this->toDatetime($this->value, 'H:i:s') ?? '';
|
||||
}
|
||||
],
|
||||
|
|
|
@ -49,9 +49,9 @@ return [
|
|||
'value' => function () {
|
||||
if ($this->props['value'] === null) {
|
||||
return $this->default();
|
||||
} else {
|
||||
return $this->toBool($this->props['value']);
|
||||
}
|
||||
|
||||
return $this->toBool($this->props['value']);
|
||||
}
|
||||
],
|
||||
'methods' => [
|
||||
|
|
|
@ -96,7 +96,7 @@ return [
|
|||
];
|
||||
},
|
||||
'save' => function ($value = null) {
|
||||
return A::pluck($value, 'id');
|
||||
return A::pluck($value, $this->store);
|
||||
},
|
||||
'validations' => [
|
||||
'max',
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue