Upgrade to 3.2.0
This commit is contained in:
40
kirby/config/fields/mixins/filepicker.php
Executable file
40
kirby/config/fields/mixins/filepicker.php
Executable 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;
|
||||
}
|
||||
]
|
||||
];
|
@@ -23,6 +23,11 @@ return [
|
||||
return $query;
|
||||
},
|
||||
],
|
||||
'computed' => [
|
||||
'options' => function (): array {
|
||||
return $this->getOptions();
|
||||
}
|
||||
],
|
||||
'methods' => [
|
||||
'getOptions' => function () {
|
||||
return Options::factory(
|
||||
|
49
kirby/config/fields/mixins/pagepicker.php
Executable file
49
kirby/config/fields/mixins/pagepicker.php
Executable 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
|
||||
];
|
||||
}
|
||||
]
|
||||
];
|
63
kirby/config/fields/mixins/picker.php
Executable file
63
kirby/config/fields/mixins/picker.php
Executable 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;
|
||||
},
|
||||
|
||||
],
|
||||
];
|
57
kirby/config/fields/mixins/upload.php
Executable file
57
kirby/config/fields/mixins/upload.php
Executable 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);
|
||||
});
|
||||
}
|
||||
]
|
||||
];
|
44
kirby/config/fields/mixins/userpicker.php
Executable file
44
kirby/config/fields/mixins/userpicker.php
Executable 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;
|
||||
}
|
||||
]
|
||||
];
|
Reference in New Issue
Block a user