Upgrade to 3.2.0

This commit is contained in:
Bastian Allgeier
2019-06-25 09:56:08 +02:00
parent 9e18cf635d
commit 9c89153d35
296 changed files with 14408 additions and 2504 deletions

View File

@@ -43,9 +43,6 @@ return [
},
],
'computed' => [
'options' => function (): array {
return $this->getOptions();
},
'default' => function () {
return $this->sanitizeOptions($this->default);
},

View File

@@ -3,7 +3,12 @@
use Kirby\Toolkit\A;
return [
'mixins' => ['min'],
'mixins' => [
'picker',
'filepicker',
'min',
'upload'
],
'props' => [
/**
* Unset inherited props
@@ -21,27 +26,6 @@ return [
return $default;
},
/**
* The placeholder text if no pages have been selected yet
*/
'empty' => function ($empty = null) {
return I18n::translate($empty, $empty);
},
/**
* Image settings for each item
*/
'image' => function (array $image = null) {
return $image ?? [];
},
/**
* Info text
*/
'info' => function (string $info = null) {
return $info;
},
/**
* Changes the layout of the selected files. Available layouts: `list`, `cards`
*/
@@ -49,48 +33,13 @@ return [
return $layout;
},
/**
* Minimum number of required files
*/
'min' => function (int $min = null) {
return $min;
},
/**
* Maximum number of allowed files
*/
'max' => function (int $max = null) {
return $max;
},
/**
* If false, only a single file can be selected
*/
'multiple' => function (bool $multiple = true) {
return $multiple;
},
/**
* Query for the files to be included
*/
'query' => function (string $query = null) {
return $query;
},
/**
* Layout size for cards: `tiny`, `small`, `medium`, `large` or `huge`
*/
'size' => function (string $size = null) {
'size' => function (string $size = 'auto') {
return $size;
},
/**
* Main text
*/
'text' => function (string $text = '{{ file.filename }}') {
return $text;
},
'value' => function ($value = null) {
return $value;
}
@@ -118,38 +67,15 @@ return [
],
'methods' => [
'fileResponse' => function ($file) {
if ($this->layout === 'list') {
$thumb = [
'width' => 100,
'height' => 100
];
} else {
$thumb = [
'width' => 400,
'height' => 400
];
}
$image = $file->panelImage($this->image, $thumb);
$model = $this->model();
$uuid = $file->parent() === $model ? $file->filename() : $file->id();
return [
'filename' => $file->filename(),
'text' => $file->toString($this->text),
'link' => $file->panelUrl(true),
'id' => $file->id(),
'uuid' => $uuid,
'url' => $file->url(),
'info' => $file->toString($this->info ?? false),
'image' => $image,
'icon' => $file->panelIcon($image),
'type' => $file->type(),
];
return $file->panelPickerData([
'image' => $this->image,
'info' => $this->info ?? false,
'model' => $this->model(),
'text' => $this->text,
]);
},
'toFiles' => function ($value = null) {
$files = [];
$kirby = kirby();
foreach (Yaml::decode($value) as $id) {
if (is_array($id) === true) {
@@ -168,16 +94,32 @@ return [
return [
[
'pattern' => '/',
'action' => function () {
'action' => function () {
$field = $this->field();
$files = $field->model()->query($field->query(), 'Kirby\Cms\Files');
$data = [];
foreach ($files as $index => $file) {
$data[] = $field->fileResponse($file);
}
return $field->filepicker([
'query' => $field->query(),
'image' => $field->image(),
'info' => $field->info(),
'text' => $field->text()
]);
}
],
[
'pattern' => 'upload',
'method' => 'POST',
'action' => function () {
$field = $this->field();
$uploads = $field->uploads();
return $data;
return $field->upload($this, $uploads, function ($file) use ($field) {
return $file->panelPickerData([
'image' => $field->image(),
'info' => $field->info(),
'model' => $field->model(),
'text' => $field->text(),
]);
});
}
]
];

View File

@@ -0,0 +1,40 @@
<?php
return [
'methods' => [
'filepicker' => function (array $params = []) {
// fetch the parent model
$model = $this->model();
// find the right default query
if (empty($params['query']) === false) {
$query = $params['query'];
} elseif (is_a($model, 'Kirby\Cms\File') === true) {
$query = 'file.siblings';
} else {
$query = $model::CLASS_ALIAS . '.files';
}
// fetch all files for the picker
$files = $model->query($query, 'Kirby\Cms\Files');
$data = [];
// prepare the response for each file
foreach ($files as $index => $file) {
if (empty($params['map']) === false) {
$data[] = $params['map']($file);
} else {
$data[] = $file->panelPickerData([
'image' => $params['image'] ?? [],
'info' => $params['info'] ?? false,
'model' => $model,
'text' => $params['text'] ?? '{{ file.filename }}',
]);
}
}
return $data;
}
]
];

View File

@@ -23,6 +23,11 @@ return [
return $query;
},
],
'computed' => [
'options' => function (): array {
return $this->getOptions();
}
],
'methods' => [
'getOptions' => function () {
return Options::factory(

View File

@@ -0,0 +1,49 @@
<?php
return [
'methods' => [
'pagepicker' => function (array $params = []) {
$query = $params['query'] ?? null;
$model = $this->model();
$site = $this->kirby()->site();
if ($query) {
$pages = $model->query($query, 'Kirby\Cms\Pages');
$self = null;
} else {
if (!$parent = $site->find($params['parent'] ?? null)) {
$parent = $site;
}
$pages = $parent->children();
$self = [
'id' => $parent->id() == '' ? null : $parent->id(),
'title' => $parent->title()->value(),
'parent' => is_a($parent->parent(), Page::class) === true ? $parent->parent()->id() : null,
];
}
$children = [];
foreach ($pages as $index => $page) {
if ($page->isReadable() === true) {
if (empty($params['map']) === false) {
$children[] = $params['map']($page);
} else {
$children[] = $page->panelPickerData([
'image' => $params['image'] ?? [],
'info' => $params['info'] ?? false,
'model' => $model,
'text' => $params['text'] ?? null,
]);
}
}
}
return [
'model' => $self,
'pages' => $children
];
}
]
];

View File

@@ -0,0 +1,63 @@
<?php
return [
'props' => [
/**
* The placeholder text if none have been selected yet
*/
'empty' => function ($empty = null) {
return I18n::translate($empty, $empty);
},
/**
* Image settings for each item
*/
'image' => function (array $image = null) {
return $image ?? [];
},
/**
* Info text for each item
*/
'info' => function (string $info = null) {
return $info;
},
/**
* The minimum number of required selected
*/
'min' => function (int $min = null) {
return $min;
},
/**
* The maximum number of allowed selected
*/
'max' => function (int $max = null) {
return $max;
},
/**
* If `false`, only a single one can be selected
*/
'multiple' => function (bool $multiple = true) {
return $multiple;
},
/**
* Query for the items to be included in the picker
*/
'query' => function (string $query = null) {
return $query;
},
/**
* Main text for each item
*/
'text' => function (string $text = '{{ file.filename }}') {
return $text;
},
],
];

View File

@@ -0,0 +1,57 @@
<?php
use Kirby\Cms\Api;
return [
'props' => [
/**
* Sets the upload options for linked files
*/
'uploads' => function ($uploads = []) {
if ($uploads === false) {
return false;
}
if (is_string($uploads) === true) {
return ['template' => $uploads];
}
if (is_array($uploads) === false) {
$uploads = [];
}
return $uploads;
},
],
'methods' => [
'upload' => function (Api $api, $params, Closure $map) {
if ($params === false) {
throw new Exception('Uploads are disabled for this field');
}
if ($parentQuery = ($params['parent'] ?? null)) {
$parent = $this->model()->query($parentQuery);
} else {
$parent = $this->model();
}
if (is_a($parent, 'Kirby\Cms\File') === true) {
$parent = $parent->parent();
}
return $api->upload(function ($source, $filename) use ($parent, $params, $map) {
$file = $parent->createFile([
'source' => $source,
'template' => $params['template'] ?? null,
'filename' => $filename,
]);
if (is_a($file, 'Kirby\Cms\File') === false) {
throw new Exception('The file could not be uploaded');
}
return $map($file);
});
}
]
];

View File

@@ -0,0 +1,44 @@
<?php
return [
'methods' => [
'userpicker' => function (array $params = []) {
// fetch the parent model
$model = $this->model();
// find the right default query
if (empty($params['query']) === false) {
$query = $params['query'];
} elseif (is_a($model, 'Kirby\Cms\User') === true) {
$query = 'user.siblings';
} else {
$query = 'kirby.users';
}
// fetch all users for the picker
$users = $model->query($query, 'Kirby\Cms\Users');
$data = [];
if (!$users) {
return [];
}
// prepare the response for each user
foreach ($users->sortBy('username', 'asc') as $index => $user) {
if (empty($params['map']) === false) {
$data[] = $params['map']($user);
} else {
$data[] = $user->panelPickerData([
'image' => $params['image'] ?? [],
'info' => $params['info'] ?? false,
'model' => $model,
'text' => $params['text'] ?? '{{ user.username }}',
]);
}
}
return $data;
}
]
];

View File

@@ -4,7 +4,7 @@ use Kirby\Toolkit\A;
use Kirby\Toolkit\I18n;
return [
'mixins' => ['min'],
'mixins' => ['min', 'pagepicker', 'picker'],
'props' => [
/**
* Unset inherited props
@@ -22,13 +22,6 @@ return [
return $this->toPages($default);
},
/**
* The placeholder text if no pages have been selected yet
*/
'empty' => function ($empty = null) {
return I18n::translate($empty, $empty);
},
/**
* Image settings for each item
*/
@@ -37,7 +30,7 @@ return [
},
/**
* Info text
* Info text for each item
*/
'info' => function (string $info = null) {
return $info;
@@ -50,27 +43,6 @@ return [
return $layout;
},
/**
* The minimum number of required selected pages
*/
'min' => function (int $min = null) {
return $min;
},
/**
* The maximum number of allowed selected pages
*/
'max' => function (int $max = null) {
return $max;
},
/**
* If `false`, only a single page can be selected
*/
'multiple' => function (bool $multiple = true) {
return $multiple;
},
/**
* Optional query to select a specific set of pages
*/
@@ -81,12 +53,12 @@ return [
/**
* Layout size for cards: `tiny`, `small`, `medium`, `large` or `huge`
*/
'size' => function (string $size = null) {
'size' => function (string $size = 'auto') {
return $size;
},
/**
* Main text
* Main text for each item
*/
'text' => function (string $text = null) {
return $text;
@@ -98,30 +70,11 @@ return [
],
'methods' => [
'pageResponse' => function ($page) {
if ($this->layout === 'list') {
$thumb = [
'width' => 100,
'height' => 100
];
} else {
$thumb = [
'width' => 400,
'height' => 400
];
}
$image = $page->panelImage($this->image, $thumb);
$model = $this->model();
return [
'text' => $page->toString($this->text ?? '{{ page.title }}'),
'link' => $page->panelUrl(true),
'id' => $page->id(),
'info' => $page->toString($this->info ?? false),
'image' => $image,
'icon' => $page->panelIcon($image),
'hasChildren' => $page->hasChildren(),
];
return $page->panelPickerData([
'image' => $this->image,
'info' => $this->info,
'text' => $this->text,
]);
},
'toPages' => function ($value = null) {
$pages = [];
@@ -146,35 +99,14 @@ return [
'pattern' => '/',
'action' => function () {
$field = $this->field();
$query = $field->query();
if ($query) {
$pages = $field->model()->query($query, 'Kirby\Cms\Pages');
$model = null;
} else {
if (!$parent = $this->site()->find($this->requestQuery('parent'))) {
$parent = $this->site();
}
$pages = $parent->children();
$model = [
'id' => $parent->id() == '' ? null : $parent->id(),
'title' => $parent->title()->value()
];
}
$children = [];
foreach ($pages as $index => $page) {
if ($page->isReadable() === true) {
$children[] = $field->pageResponse($page);
}
}
return [
'model' => $model,
'pages' => $children
];
return $field->pagepicker([
'image' => $field->image(),
'info' => $field->info(),
'parent' => $this->requestQuery('parent'),
'query' => $field->query(),
'text' => $field->text()
]);
}
]
];

View File

@@ -19,9 +19,6 @@ return [
},
],
'computed' => [
'options' => function (): array {
return $this->getOptions();
},
'default' => function () {
return $this->sanitizeOption($this->default);
},

View File

@@ -14,5 +14,11 @@ return [
'icon' => function (string $icon = null) {
return $icon;
},
/**
* Custom placeholder string for empty option.
*/
'placeholder' => function (string $placeholder = '—') {
return $placeholder;
},
]
];

View File

@@ -43,9 +43,6 @@ return [
},
],
'computed' => [
'options' => function () {
return $this->getOptions();
},
'default' => function (): array {
return $this->toTags($this->default);
},
@@ -55,6 +52,10 @@ return [
],
'methods' => [
'toTags' => function ($value) {
if (is_null($value) === true) {
return [];
}
$options = $this->options();
// transform into value-text objects

View File

@@ -1,6 +1,7 @@
<?php
return [
'mixins' => ['filepicker', 'upload'],
'props' => [
/**
* Unset inherited props
@@ -44,6 +45,13 @@ return [
return $files;
},
/**
* Sets the font family (sans or monospace)
*/
'font' => function (string $font = null) {
return $font === 'monospace' ? 'monospace' : 'sans-serif';
},
/**
* Maximum number of allowed characters
*/
@@ -65,24 +73,6 @@ return [
return $size;
},
/**
* Sets the upload options for linked files
*/
'uploads' => function ($uploads = []) {
if ($uploads === false) {
return false;
}
if (is_string($uploads) === true) {
return ['template' => $uploads];
}
if (is_array($uploads) === false) {
$uploads = [];
}
return $uploads;
},
'value' => function (string $value = null) {
return trim($value);
@@ -93,66 +83,13 @@ return [
[
'pattern' => 'files',
'action' => function () {
$field = $this->field();
$model = $field->model();
if (empty($filed->files['query']) === false) {
$query = $filed->files['query'];
} elseif (is_a($model, 'Kirby\Cms\File') === true) {
$query = 'file.siblings';
} else {
$query = $model::CLASS_ALIAS . '.files';
}
$files = $model->query($query, 'Kirby\Cms\Files');
$data = [];
foreach ($files as $index => $file) {
$image = $file->panelImage($field->files['image'] ?? []);
$model = $field->model();
$data[] = [
'filename' => $file->filename(),
'dragText' => $file->dragText(),
'image' => $image,
'icon' => $file->panelIcon($image)
];
}
return $data;
return $this->field()->filepicker($this->field()->files());
}
],
[
'pattern' => 'upload',
'action' => function () {
$field = $this->field();
$uploads = $field->uploads();
if ($uploads === false) {
throw new Exception('Uploads are disabled for this field');
}
if ($parentQuery = ($uploads['parent'] ?? null)) {
$parent = $field->model()->query($parentQuery);
} else {
$parent = $field->model();
}
if (is_a($parent, 'Kirby\Cms\File') === true) {
$parent = $parent->parent();
}
return $this->upload(function ($source, $filename) use ($field, $parent, $uploads) {
$file = $parent->createFile([
'source' => $source,
'template' => $uploads['template'] ?? null,
'filename' => $filename,
]);
if (is_a($file, 'Kirby\Cms\File') === false) {
throw new Exception('The file could not be uploaded');
}
return $this->field()->upload($this, $this->field()->uploads(), function ($file) {
return [
'filename' => $file->filename(),
'dragText' => $file->dragText(),

View File

@@ -1,7 +1,7 @@
<?php
return [
'mixins' => ['min', 'selector'],
'mixins' => ['min', 'picker', 'userpicker'],
'props' => [
/**
* Unset inherited props
@@ -29,56 +29,17 @@ return [
return $this->toUsers($default);
},
/**
* The placeholder text if none have been selected yet
*/
'empty' => function ($empty = null) {
return I18n::translate($empty, $empty);
},
/**
* The minimum number of required selected
*/
'min' => function (int $min = null) {
return $min;
},
/**
* The maximum number of allowed selected
*/
'max' => function (int $max = null) {
return $max;
},
/**
* If `false`, only a single one can be selected
*/
'multiple' => function (bool $multiple = true) {
return $multiple;
},
'value' => function ($value = null) {
return $this->toUsers($value);
},
],
'methods' => [
'userResponse' => function ($user) {
$avatar = function ($user) {
if ($avatar = $user->avatar()) {
return [
'url' => $avatar->crop(512)->url()
];
}
return null;
};
return [
'username' => $user->username(),
'id' => $user->id(),
'email' => $user->email(),
'avatar' => $avatar($user)
];
return $user->panelPickerData([
'info' => $this->info,
'image' => $this->image,
'text' => $this->text,
]);
},
'toUsers' => function ($value = null) {
$users = [];
@@ -97,6 +58,23 @@ return [
return $users;
}
],
'api' => function () {
return [
[
'pattern' => '/',
'action' => function () {
$field = $this->field();
return $field->userpicker([
'query' => $field->query(),
'image' => $field->image(),
'info' => $field->info(),
'text' => $field->text()
]);
}
]
];
},
'save' => function ($value = null) {
return A::pluck($value, 'email');
},