Upgrade to 3.3.0
This commit is contained in:
@@ -1,40 +1,14 @@
|
||||
<?php
|
||||
|
||||
use Kirby\Cms\FilePicker;
|
||||
|
||||
return [
|
||||
'methods' => [
|
||||
'filepicker' => function (array $params = []) {
|
||||
|
||||
// fetch the parent model
|
||||
$model = $this->model();
|
||||
$params['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;
|
||||
return (new FilePicker($params))->toArray();
|
||||
}
|
||||
]
|
||||
];
|
||||
|
@@ -1,49 +1,14 @@
|
||||
<?php
|
||||
|
||||
use Kirby\Cms\PagePicker;
|
||||
|
||||
return [
|
||||
'methods' => [
|
||||
'pagepicker' => function (array $params = []) {
|
||||
$query = $params['query'] ?? null;
|
||||
$model = $this->model();
|
||||
$site = $this->kirby()->site();
|
||||
// inject the current model
|
||||
$params['model'] = $this->model();
|
||||
|
||||
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(), 'Kirby\Cms\Page') === 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
|
||||
];
|
||||
return (new PagePicker($params))->toArray();
|
||||
}
|
||||
]
|
||||
];
|
||||
|
@@ -53,6 +53,13 @@ return [
|
||||
return $query;
|
||||
},
|
||||
|
||||
/**
|
||||
* Enable/disable the search field in the picker
|
||||
*/
|
||||
'search' => function (bool $search = true) {
|
||||
return $search;
|
||||
},
|
||||
|
||||
/**
|
||||
* Main text for each item
|
||||
*/
|
||||
|
@@ -1,44 +1,13 @@
|
||||
<?php
|
||||
|
||||
use Kirby\Cms\UserPicker;
|
||||
|
||||
return [
|
||||
'methods' => [
|
||||
'userpicker' => function (array $params = []) {
|
||||
$params['model'] = $this->model();
|
||||
|
||||
// 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;
|
||||
return (new UserPicker($params))->toArray();
|
||||
}
|
||||
]
|
||||
];
|
||||
|
Reference in New Issue
Block a user