Upgrade to 4.0.0
This commit is contained in:
98
kirby/config/fields/color.php
Normal file
98
kirby/config/fields/color.php
Normal file
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
|
||||
use Kirby\Exception\InvalidArgumentException;
|
||||
use Kirby\Toolkit\A;
|
||||
use Kirby\Toolkit\Str;
|
||||
|
||||
return [
|
||||
'props' => [
|
||||
/**
|
||||
* Unset inherited props
|
||||
*/
|
||||
'after' => null,
|
||||
'before' => null,
|
||||
|
||||
/**
|
||||
* Whether to allow alpha transparency in the color
|
||||
*/
|
||||
'alpha' => function (bool $alpha = false) {
|
||||
return $alpha;
|
||||
},
|
||||
/**
|
||||
* The CSS format (hex, rgb, hsl) to display and store the value
|
||||
*/
|
||||
'format' => function (string $format = 'hex'): string {
|
||||
if (in_array($format, ['hex', 'hsl', 'rgb']) === false) {
|
||||
throw new InvalidArgumentException('Unsupported format for color field (supported: hex, rgb, hsl)');
|
||||
}
|
||||
|
||||
return $format;
|
||||
},
|
||||
/**
|
||||
* Change mode to disable the color picker (`input`) or to only
|
||||
* show the `options` as toggles
|
||||
*/
|
||||
'mode' => function (string $mode = 'picker'): string {
|
||||
if (in_array($mode, ['picker', 'input', 'options']) === false) {
|
||||
throw new InvalidArgumentException('Unsupported mode for color field (supported: picker, input, options)');
|
||||
}
|
||||
|
||||
return $mode;
|
||||
},
|
||||
/**
|
||||
* List of colors that will be shown as buttons
|
||||
* to directly select them
|
||||
*/
|
||||
'options' => function (array $options = []): array {
|
||||
return $options;
|
||||
}
|
||||
],
|
||||
'computed' => [
|
||||
'default' => function (): string {
|
||||
return Str::lower($this->default);
|
||||
},
|
||||
'options' => function (): array {
|
||||
return A::map(array_keys($this->options), fn ($key) => [
|
||||
'value' => $this->options[$key],
|
||||
'text' => is_string($key) ? $key : null
|
||||
]);
|
||||
}
|
||||
],
|
||||
'validations' => [
|
||||
'color' => function ($value) {
|
||||
if (empty($value) === true) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (
|
||||
$this->format === 'hex' &&
|
||||
preg_match('/^#([\da-f]{3,4}){1,2}$/i', $value) !== 1
|
||||
) {
|
||||
throw new InvalidArgumentException([
|
||||
'key' => 'validation.color',
|
||||
'data' => ['format' => 'hex']
|
||||
]);
|
||||
}
|
||||
|
||||
if (
|
||||
$this->format === 'rgb' &&
|
||||
preg_match('/^rgba?\(\s*(\d{1,3})(%?)(?:,|\s)+(\d{1,3})(%?)(?:,|\s)+(\d{1,3})(%?)(?:,|\s|\/)*(\d*(?:\.\d+)?)(%?)\s*\)?$/i', $value) !== 1
|
||||
) {
|
||||
throw new InvalidArgumentException([
|
||||
'key' => 'validation.color',
|
||||
'data' => ['format' => 'rgb']
|
||||
]);
|
||||
}
|
||||
|
||||
if (
|
||||
$this->format === 'hsl' &&
|
||||
preg_match('/^hsla?\(\s*(\d{1,3}\.?\d*)(deg|rad|grad|turn)?(?:,|\s)+(\d{1,3})%(?:,|\s)+(\d{1,3})%(?:,|\s|\/)*(\d*(?:\.\d+)?)(%?)\s*\)?$/i', $value) !== 1
|
||||
) {
|
||||
throw new InvalidArgumentException([
|
||||
'key' => 'validation.color',
|
||||
'data' => ['format' => 'hsl']
|
||||
]);
|
||||
}
|
||||
}
|
||||
]
|
||||
];
|
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
|
||||
use Kirby\Cms\ModelWithContent;
|
||||
use Kirby\Data\Data;
|
||||
use Kirby\Toolkit\A;
|
||||
|
||||
@@ -36,7 +37,10 @@ return [
|
||||
'parentModel' => function () {
|
||||
if (
|
||||
is_string($this->parent) === true &&
|
||||
$model = $this->model()->query($this->parent, 'Kirby\Cms\Model')
|
||||
$model = $this->model()->query(
|
||||
$this->parent,
|
||||
ModelWithContent::class
|
||||
)
|
||||
) {
|
||||
return $model;
|
||||
}
|
||||
|
@@ -14,13 +14,6 @@ return [
|
||||
'icon' => null,
|
||||
'placeholder' => null,
|
||||
'required' => null,
|
||||
'translate' => null,
|
||||
|
||||
/**
|
||||
* If `false`, the prepended number will be hidden
|
||||
*/
|
||||
'numbered' => function (bool $numbered = true) {
|
||||
return $numbered;
|
||||
}
|
||||
'translate' => null
|
||||
]
|
||||
];
|
||||
|
@@ -1,3 +1,5 @@
|
||||
<?php
|
||||
|
||||
return [];
|
||||
return [
|
||||
'hidden' => true
|
||||
];
|
||||
|
@@ -12,7 +12,6 @@ return [
|
||||
'before' => null,
|
||||
'default' => null,
|
||||
'disabled' => null,
|
||||
'icon' => null,
|
||||
'placeholder' => null,
|
||||
'required' => null,
|
||||
'translate' => null,
|
||||
|
156
kirby/config/fields/link.php
Normal file
156
kirby/config/fields/link.php
Normal file
@@ -0,0 +1,156 @@
|
||||
<?php
|
||||
|
||||
use Kirby\Exception\InvalidArgumentException;
|
||||
use Kirby\Http\Url;
|
||||
use Kirby\Toolkit\Str;
|
||||
use Kirby\Toolkit\V;
|
||||
|
||||
return [
|
||||
'props' => [
|
||||
'after' => null,
|
||||
'before' => null,
|
||||
'icon' => null,
|
||||
'placeholder' => null,
|
||||
|
||||
/**
|
||||
* @values 'anchor', 'url, 'page, 'file', 'email', 'tel', 'custom'
|
||||
*/
|
||||
'options' => function (array|null $options = null): array {
|
||||
return $options ?? [
|
||||
'url',
|
||||
'page',
|
||||
'file',
|
||||
'email',
|
||||
'tel',
|
||||
'anchor',
|
||||
'custom'
|
||||
];
|
||||
},
|
||||
'value' => function (string|null $value = null) {
|
||||
return $value ?? '';
|
||||
}
|
||||
],
|
||||
'methods' => [
|
||||
'activeTypes' => function () {
|
||||
return array_filter($this->availableTypes(), function (string $type) {
|
||||
return in_array($type, $this->props['options']) === true;
|
||||
}, ARRAY_FILTER_USE_KEY);
|
||||
},
|
||||
'availableTypes' => function () {
|
||||
return [
|
||||
'anchor' => [
|
||||
'detect' => function (string $value): bool {
|
||||
return Str::startsWith($value, '#') === true;
|
||||
},
|
||||
'link' => function (string $value): string {
|
||||
return $value;
|
||||
},
|
||||
'validate' => function (string $value): bool {
|
||||
return Str::startsWith($value, '#') === true;
|
||||
},
|
||||
],
|
||||
'email' => [
|
||||
'detect' => function (string $value): bool {
|
||||
return Str::startsWith($value, 'mailto:') === true;
|
||||
},
|
||||
'link' => function (string $value): string {
|
||||
return str_replace('mailto:', '', $value);
|
||||
},
|
||||
'validate' => function (string $value): bool {
|
||||
return V::email($value);
|
||||
},
|
||||
],
|
||||
'file' => [
|
||||
'detect' => function (string $value): bool {
|
||||
return Str::startsWith($value, 'file://') === true;
|
||||
},
|
||||
'link' => function (string $value): string {
|
||||
return $value;
|
||||
},
|
||||
'validate' => function (string $value): bool {
|
||||
return V::uuid($value, 'file');
|
||||
},
|
||||
],
|
||||
'page' => [
|
||||
'detect' => function (string $value): bool {
|
||||
return Str::startsWith($value, 'page://') === true;
|
||||
},
|
||||
'link' => function (string $value): string {
|
||||
return $value;
|
||||
},
|
||||
'validate' => function (string $value): bool {
|
||||
return V::uuid($value, 'page');
|
||||
},
|
||||
],
|
||||
'tel' => [
|
||||
'detect' => function (string $value): bool {
|
||||
return Str::startsWith($value, 'tel:') === true;
|
||||
},
|
||||
'link' => function (string $value): string {
|
||||
return str_replace('tel:', '', $value);
|
||||
},
|
||||
'validate' => function (string $value): bool {
|
||||
return V::tel($value);
|
||||
},
|
||||
],
|
||||
'url' => [
|
||||
'detect' => function (string $value): bool {
|
||||
return Str::startsWith($value, 'http://') === true || Str::startsWith($value, 'https://') === true;
|
||||
},
|
||||
'link' => function (string $value): string {
|
||||
return $value;
|
||||
},
|
||||
'validate' => function (string $value): bool {
|
||||
return V::url($value);
|
||||
},
|
||||
],
|
||||
|
||||
// needs to come last
|
||||
'custom' => [
|
||||
'detect' => function (string $value): bool {
|
||||
return true;
|
||||
},
|
||||
'link' => function (string $value): string {
|
||||
return $value;
|
||||
},
|
||||
'validate' => function (): bool {
|
||||
return true;
|
||||
},
|
||||
]
|
||||
];
|
||||
},
|
||||
],
|
||||
'validations' => [
|
||||
'value' => function (string|null $value) {
|
||||
if (empty($value) === true) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$detected = false;
|
||||
|
||||
foreach ($this->activeTypes() as $type => $options) {
|
||||
if ($options['detect']($value) !== true) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$link = $options['link']($value);
|
||||
$detected = true;
|
||||
|
||||
if ($options['validate']($link) === false) {
|
||||
throw new InvalidArgumentException([
|
||||
'key' => 'validation.' . $type
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
// none of the configured types has been detected
|
||||
if ($detected === false) {
|
||||
throw new InvalidArgumentException([
|
||||
'key' => 'validation.linkType'
|
||||
]);
|
||||
}
|
||||
|
||||
return true;
|
||||
},
|
||||
]
|
||||
];
|
@@ -7,6 +7,12 @@ return [
|
||||
*/
|
||||
'marks' => function ($marks = true) {
|
||||
return $marks;
|
||||
},
|
||||
/**
|
||||
* Sets the allowed nodes. Available nodes: `bulletList`, `orderedList`
|
||||
*/
|
||||
'nodes' => function ($nodes = null) {
|
||||
return $nodes;
|
||||
}
|
||||
],
|
||||
'computed' => [
|
||||
|
@@ -12,7 +12,7 @@ return [
|
||||
},
|
||||
|
||||
/**
|
||||
* Layout size for cards: `tiny`, `small`, `medium`, `large` or `huge`
|
||||
* Layout size for cards: `tiny`, `small`, `medium`, `large`, `huge`, `full`
|
||||
*/
|
||||
'size' => function (string $size = 'auto') {
|
||||
return $size;
|
||||
|
@@ -36,7 +36,7 @@ return [
|
||||
},
|
||||
'sanitizeOption' => function ($value) {
|
||||
$options = array_column($this->options(), 'value');
|
||||
return in_array($value, $options, true) === true ? $value : null;
|
||||
return in_array($value, $options) === true ? $value : null;
|
||||
},
|
||||
'sanitizeOptions' => function ($values) {
|
||||
$options = array_column($this->options(), 'value');
|
||||
|
@@ -3,6 +3,7 @@
|
||||
use Kirby\Cms\Api;
|
||||
use Kirby\Cms\File;
|
||||
use Kirby\Exception\Exception;
|
||||
use Kirby\Exception\InvalidArgumentException;
|
||||
|
||||
return [
|
||||
'props' => [
|
||||
@@ -22,18 +23,23 @@ return [
|
||||
$uploads = [];
|
||||
}
|
||||
|
||||
$template = $uploads['template'] ?? null;
|
||||
$uploads['accept'] = '*';
|
||||
|
||||
if ($template = $uploads['template'] ?? null) {
|
||||
// get parent object for upload target
|
||||
$parent = $this->uploadParent($uploads['parent'] ?? null);
|
||||
|
||||
if ($parent === null) {
|
||||
throw new InvalidArgumentException('"' . $uploads['parent'] . '" could not be resolved as a valid parent for the upload');
|
||||
}
|
||||
|
||||
if ($template) {
|
||||
$file = new File([
|
||||
'filename' => 'tmp',
|
||||
'parent' => $this->model(),
|
||||
'parent' => $parent,
|
||||
'template' => $template
|
||||
]);
|
||||
|
||||
$uploads['accept'] = $file->blueprint()->acceptMime();
|
||||
} else {
|
||||
$uploads['accept'] = '*';
|
||||
}
|
||||
|
||||
return $uploads;
|
||||
@@ -45,15 +51,7 @@ return [
|
||||
throw new Exception('Uploads are disabled for this field');
|
||||
}
|
||||
|
||||
if ($parentQuery = ($params['parent'] ?? null)) {
|
||||
$parent = $this->model()->query($parentQuery);
|
||||
} else {
|
||||
$parent = $this->model();
|
||||
}
|
||||
|
||||
if ($parent instanceof File) {
|
||||
$parent = $parent->parent();
|
||||
}
|
||||
$parent = $this->uploadParent($params['parent'] ?? null);
|
||||
|
||||
return $api->upload(function ($source, $filename) use ($parent, $params, $map) {
|
||||
$props = [
|
||||
@@ -71,6 +69,19 @@ return [
|
||||
|
||||
return $map($file, $parent);
|
||||
});
|
||||
},
|
||||
'uploadParent' => function (string $parentQuery = null) {
|
||||
$parent = $this->model();
|
||||
|
||||
if ($parentQuery) {
|
||||
$parent = $parent->query($parentQuery);
|
||||
}
|
||||
|
||||
if ($parent instanceof File) {
|
||||
$parent = $parent->parent();
|
||||
}
|
||||
|
||||
return $parent;
|
||||
}
|
||||
]
|
||||
];
|
||||
|
@@ -1,35 +1,23 @@
|
||||
<?php
|
||||
|
||||
use Kirby\Toolkit\Str;
|
||||
use Kirby\Toolkit\V;
|
||||
|
||||
return [
|
||||
'extends' => 'tags',
|
||||
'props' => [
|
||||
/**
|
||||
* Unset inherited props
|
||||
* If set to `all`, any type of input is accepted. If set to `options` only the predefined options are accepted as input.
|
||||
*/
|
||||
'accept' => null,
|
||||
'accept' => function ($value = 'options') {
|
||||
return V::in($value, ['all', 'options']) ? $value : 'all';
|
||||
},
|
||||
/**
|
||||
* Custom icon to replace the arrow down.
|
||||
*/
|
||||
'icon' => function (string $icon = null) {
|
||||
'icon' => function (string $icon = 'checklist') {
|
||||
return $icon;
|
||||
},
|
||||
/**
|
||||
* Enable/disable the search in the dropdown
|
||||
* Also limit displayed items (display: 20)
|
||||
* and set minimum number of characters to search (min: 3)
|
||||
*/
|
||||
'search' => function ($search = true) {
|
||||
return $search;
|
||||
},
|
||||
/**
|
||||
* If `true`, selected entries will be sorted
|
||||
* according to their position in the dropdown
|
||||
*/
|
||||
'sort' => function (bool $sort = false) {
|
||||
return $sort;
|
||||
},
|
||||
],
|
||||
'methods' => [
|
||||
'toValues' => function ($value) {
|
||||
|
@@ -47,7 +47,7 @@ return [
|
||||
},
|
||||
'fields' => function () {
|
||||
if (empty($this->fields) === true) {
|
||||
throw new Exception('Please provide some fields for the object');
|
||||
return [];
|
||||
}
|
||||
|
||||
return $this->form()->fields()->toArray();
|
||||
|
@@ -1,8 +1,11 @@
|
||||
<?php
|
||||
|
||||
use Kirby\Data\Data;
|
||||
use Kirby\Exception\InvalidArgumentException;
|
||||
use Kirby\Form\Form;
|
||||
use Kirby\Toolkit\A;
|
||||
use Kirby\Toolkit\I18n;
|
||||
use Kirby\Toolkit\Str;
|
||||
|
||||
return [
|
||||
'mixins' => ['min'],
|
||||
@@ -49,7 +52,7 @@ return [
|
||||
/**
|
||||
* Fields setup for the structure form. Works just like fields in regular forms.
|
||||
*/
|
||||
'fields' => function (array $fields) {
|
||||
'fields' => function (array $fields = []) {
|
||||
return $fields;
|
||||
},
|
||||
/**
|
||||
@@ -99,57 +102,54 @@ return [
|
||||
},
|
||||
'fields' => function () {
|
||||
if (empty($this->fields) === true) {
|
||||
throw new Exception('Please provide some fields for the structure');
|
||||
return [];
|
||||
}
|
||||
|
||||
return $this->form()->fields()->toArray();
|
||||
},
|
||||
'columns' => function () {
|
||||
$columns = [];
|
||||
$mobile = 0;
|
||||
$columns = [];
|
||||
$blueprint = $this->columns;
|
||||
|
||||
if (empty($this->columns) === true) {
|
||||
foreach ($this->fields as $field) {
|
||||
// Skip hidden and unsaveable fields
|
||||
// They should never be included as column
|
||||
if ($field['type'] === 'hidden' || $field['saveable'] === false) {
|
||||
continue;
|
||||
}
|
||||
// if no custom columns have been defined,
|
||||
// gather all fields as columns
|
||||
if (empty($blueprint) === true) {
|
||||
// skip hidden fields
|
||||
$fields = array_filter(
|
||||
$this->fields,
|
||||
fn ($field) =>
|
||||
$field['type'] !== 'hidden' && $field['hidden'] !== true
|
||||
);
|
||||
$fields = array_column($fields, 'name');
|
||||
$blueprint = array_fill_keys($fields, true);
|
||||
}
|
||||
|
||||
$columns[$field['name']] = [
|
||||
'type' => $field['type'],
|
||||
'label' => $field['label'] ?? $field['name']
|
||||
];
|
||||
foreach ($blueprint as $name => $column) {
|
||||
$field = $this->fields[$name] ?? null;
|
||||
|
||||
// Skip empty and unsaveable fields
|
||||
// They should never be included as column
|
||||
if (
|
||||
empty($field) === true ||
|
||||
$field['saveable'] === false
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
foreach ($this->columns as $columnName => $columnProps) {
|
||||
if (is_array($columnProps) === false) {
|
||||
$columnProps = [];
|
||||
}
|
||||
|
||||
$field = $this->fields[$columnName] ?? null;
|
||||
|
||||
if (
|
||||
empty($field) === true ||
|
||||
$field['saveable'] === false
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (($columnProps['mobile'] ?? false) === true) {
|
||||
$mobile++;
|
||||
}
|
||||
|
||||
$columns[$columnName] = array_merge([
|
||||
'type' => $field['type'],
|
||||
'label' => $field['label'] ?? $field['name']
|
||||
], $columnProps);
|
||||
if (is_array($column) === false) {
|
||||
$column = [];
|
||||
}
|
||||
|
||||
$column['type'] ??= $field['type'];
|
||||
$column['label'] ??= $field['label'] ?? $name;
|
||||
$column['label'] = I18n::translate($column['label'], $column['label']);
|
||||
|
||||
$columns[$name] = $column;
|
||||
}
|
||||
|
||||
// make the first column visible on mobile
|
||||
// if no other mobile columns are defined
|
||||
if ($mobile === 0) {
|
||||
if (in_array(true, array_column($columns, 'mobile')) === false) {
|
||||
$columns[array_key_first($columns)]['mobile'] = true;
|
||||
}
|
||||
|
||||
@@ -179,28 +179,47 @@ return [
|
||||
]);
|
||||
},
|
||||
],
|
||||
'api' => function () {
|
||||
return [
|
||||
[
|
||||
'pattern' => 'validate',
|
||||
'method' => 'ALL',
|
||||
'action' => function () {
|
||||
return array_values($this->field()->form($this->requestBody())->errors());
|
||||
}
|
||||
]
|
||||
];
|
||||
},
|
||||
'save' => function ($value) {
|
||||
$data = [];
|
||||
|
||||
foreach ($value as $row) {
|
||||
$data[] = $this->form($row)->content();
|
||||
$row = $this->form($row)->content();
|
||||
|
||||
// remove frontend helper id
|
||||
unset($row['_id']);
|
||||
|
||||
$data[] = $row;
|
||||
}
|
||||
|
||||
return $data;
|
||||
},
|
||||
'validations' => [
|
||||
'min',
|
||||
'max'
|
||||
'max',
|
||||
'structure' => function ($value) {
|
||||
if (empty($value) === true) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$values = A::wrap($value);
|
||||
|
||||
foreach ($values as $index => $value) {
|
||||
$form = $this->form($value);
|
||||
|
||||
foreach ($form->fields() as $field) {
|
||||
$errors = $field->errors();
|
||||
|
||||
if (empty($errors) === false) {
|
||||
throw new InvalidArgumentException([
|
||||
'key' => 'structure.validation',
|
||||
'data' => [
|
||||
'field' => $field->label() ?? Str::ucfirst($field->name()),
|
||||
'index' => $index + 1
|
||||
]
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
];
|
||||
|
@@ -46,12 +46,27 @@ return [
|
||||
'max' => function (int $max = null) {
|
||||
return $max;
|
||||
},
|
||||
/**
|
||||
* Enable/disable the search in the dropdown
|
||||
* Also limit displayed items (display: 20)
|
||||
* and set minimum number of characters to search (min: 3)
|
||||
*/
|
||||
'search' => function (bool|array $search = true) {
|
||||
return $search;
|
||||
},
|
||||
/**
|
||||
* Custom tags separator, which will be used to store tags in the content file
|
||||
*/
|
||||
'separator' => function (string $separator = ',') {
|
||||
return $separator;
|
||||
},
|
||||
/**
|
||||
* If `true`, selected entries will be sorted
|
||||
* according to their position in the dropdown
|
||||
*/
|
||||
'sort' => function (bool $sort = false) {
|
||||
return $sort;
|
||||
},
|
||||
],
|
||||
'computed' => [
|
||||
'default' => function (): array {
|
||||
|
@@ -27,6 +27,13 @@ return [
|
||||
return $counter;
|
||||
},
|
||||
|
||||
/**
|
||||
* Sets the font family (sans or monospace)
|
||||
*/
|
||||
'font' => function (string $font = null) {
|
||||
return $font === 'monospace' ? 'monospace' : 'sans-serif';
|
||||
},
|
||||
|
||||
/**
|
||||
* Maximum number of allowed characters
|
||||
*/
|
||||
|
@@ -24,18 +24,8 @@ return [
|
||||
/**
|
||||
* Default selected user(s) when a new page/file/user is created
|
||||
*/
|
||||
'default' => function ($default = null) {
|
||||
if ($default === false) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if ($default === null && $user = $this->kirby()->user()) {
|
||||
return [
|
||||
$this->userResponse($user)
|
||||
];
|
||||
}
|
||||
|
||||
return $this->toUsers($default);
|
||||
'default' => function (string|array|bool|null $default = null) {
|
||||
return $default;
|
||||
},
|
||||
|
||||
'value' => function ($value = null) {
|
||||
@@ -43,10 +33,22 @@ return [
|
||||
},
|
||||
],
|
||||
'computed' => [
|
||||
/**
|
||||
* Unset inherited computed
|
||||
*/
|
||||
'default' => null
|
||||
'default' => function (): array {
|
||||
if ($this->default === false) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (
|
||||
$this->default === true &&
|
||||
$user = $this->kirby()->user()
|
||||
) {
|
||||
return [
|
||||
$this->userResponse($user)
|
||||
];
|
||||
}
|
||||
|
||||
return $this->toUsers($this->default);
|
||||
}
|
||||
],
|
||||
'methods' => [
|
||||
'userResponse' => function ($user) {
|
||||
@@ -57,7 +59,7 @@ return [
|
||||
'text' => $this->text,
|
||||
]);
|
||||
},
|
||||
'toUsers' => function ($value = null) {
|
||||
'toUsers' => function ($value = null): array {
|
||||
$users = [];
|
||||
$kirby = App::instance();
|
||||
|
||||
|
@@ -1,9 +1,23 @@
|
||||
<?php
|
||||
|
||||
use Kirby\Exception\InvalidArgumentException;
|
||||
use Kirby\Sane\Sane;
|
||||
use Kirby\Toolkit\V;
|
||||
|
||||
return [
|
||||
'props' => [
|
||||
/**
|
||||
* Enables/disables the character counter in the top right corner
|
||||
*/
|
||||
'counter' => function (bool $counter = true) {
|
||||
return $counter;
|
||||
},
|
||||
/**
|
||||
* Available heading levels
|
||||
*/
|
||||
'headings' => function (array|null $headings = null) {
|
||||
return array_intersect($headings ?? range(1, 6), range(1, 6));
|
||||
},
|
||||
/**
|
||||
* Enables inline mode, which will not wrap new lines in paragraphs and creates hard breaks instead.
|
||||
*
|
||||
@@ -13,18 +27,37 @@ return [
|
||||
return $inline;
|
||||
},
|
||||
/**
|
||||
* Sets the allowed HTML formats. Available formats: `bold`, `italic`, `underline`, `strike`, `code`, `link`, `email`. Activate them all by passing `true`. Deactivate them all by passing `false`
|
||||
* Sets the allowed HTML formats. Available formats: `bold`, `italic`, `underline`, `strike`, `code`, `link`, `email`. Activate/deactivate them all by passing `true`/`false`. Default marks are `bold`, `italic`, `underline`, `strike`, `link`, `email`
|
||||
* @param array|bool $marks
|
||||
*/
|
||||
'marks' => function ($marks = true) {
|
||||
'marks' => function ($marks = null) {
|
||||
return $marks;
|
||||
},
|
||||
/**
|
||||
* Sets the allowed nodes. Available nodes: `paragraph`, `heading`, `bulletList`, `orderedList`. Activate/deactivate them all by passing `true`/`false`. Default nodes are `paragraph`, `heading`, `bulletList`, `orderedList`.
|
||||
* Maximum number of allowed characters
|
||||
*/
|
||||
'maxlength' => function (int $maxlength = null) {
|
||||
return $maxlength;
|
||||
},
|
||||
|
||||
/**
|
||||
* Minimum number of required characters
|
||||
*/
|
||||
'minlength' => function (int $minlength = null) {
|
||||
return $minlength;
|
||||
},
|
||||
/**
|
||||
* Sets the allowed nodes. Available nodes: `paragraph`, `heading`, `bulletList`, `orderedList`, `quote`. Activate/deactivate them all by passing `true`/`false`. Default nodes are `paragraph`, `heading`, `bulletList`, `orderedList`.
|
||||
* @param array|bool|null $nodes
|
||||
*/
|
||||
'nodes' => function ($nodes = null) {
|
||||
return $nodes;
|
||||
},
|
||||
/**
|
||||
* Toolbar options, incl. `marks` (to narrow down which marks should have toolbar buttons), `nodes` (to narrow down which nodes should have toolbar dropdown entries) and `inline` to set the position of the toolbar (false = sticking on top of the field)
|
||||
*/
|
||||
'toolbar' => function ($toolbar = null) {
|
||||
return $toolbar;
|
||||
}
|
||||
],
|
||||
'computed' => [
|
||||
@@ -33,4 +66,28 @@ return [
|
||||
return Sane::sanitize($value, 'html');
|
||||
}
|
||||
],
|
||||
'validations' => [
|
||||
'minlength' => function ($value) {
|
||||
if (
|
||||
$this->minlength &&
|
||||
V::minLength(strip_tags($value), $this->minlength) === false
|
||||
) {
|
||||
throw new InvalidArgumentException([
|
||||
'key' => 'validation.minlength',
|
||||
'data' => ['min' => $this->minlength]
|
||||
]);
|
||||
}
|
||||
},
|
||||
'maxlength' => function ($value) {
|
||||
if (
|
||||
$this->maxlength &&
|
||||
V::maxLength(strip_tags($value), $this->maxlength) === false
|
||||
) {
|
||||
throw new InvalidArgumentException([
|
||||
'key' => 'validation.maxlength',
|
||||
'data' => ['max' => $this->maxlength]
|
||||
]);
|
||||
}
|
||||
},
|
||||
]
|
||||
];
|
||||
|
Reference in New Issue
Block a user