Update to Kirby 5
This commit is contained in:
parent
5d9979fca8
commit
0fefc5e2e1
472 changed files with 30853 additions and 10301 deletions
|
@ -1,7 +1,5 @@
|
|||
<?php
|
||||
|
||||
use Kirby\Cms\Page;
|
||||
use Kirby\Cms\Site;
|
||||
use Kirby\Form\Form;
|
||||
|
||||
return [
|
||||
|
@ -12,45 +10,19 @@ return [
|
|||
],
|
||||
'computed' => [
|
||||
'form' => function () {
|
||||
$fields = $this->fields;
|
||||
$disabled = $this->model->permissions()->update() === false;
|
||||
$lang = $this->model->kirby()->languageCode();
|
||||
$content = $this->model->content($lang)->toArray();
|
||||
|
||||
if ($disabled === true) {
|
||||
foreach ($fields as $key => $props) {
|
||||
$fields[$key]['disabled'] = true;
|
||||
}
|
||||
}
|
||||
|
||||
return new Form([
|
||||
'fields' => $fields,
|
||||
'values' => $content,
|
||||
'model' => $this->model,
|
||||
'strict' => true
|
||||
]);
|
||||
return new Form(
|
||||
fields: $this->fields,
|
||||
model: $this->model,
|
||||
language: 'current'
|
||||
);
|
||||
},
|
||||
'fields' => function () {
|
||||
$fields = $this->form->fields()->toArray();
|
||||
|
||||
if (
|
||||
$this->model instanceof Page ||
|
||||
$this->model instanceof Site
|
||||
) {
|
||||
// the title should never be updated directly via
|
||||
// fields section to avoid conflicts with the rename dialog
|
||||
unset($fields['title']);
|
||||
}
|
||||
|
||||
foreach ($fields as $index => $props) {
|
||||
unset($fields[$index]['value']);
|
||||
}
|
||||
|
||||
return $fields;
|
||||
return $this->form->fields()->toProps();
|
||||
}
|
||||
],
|
||||
'methods' => [
|
||||
'errors' => function () {
|
||||
$this->form->fill($this->model->content('current')->toArray());
|
||||
return $this->form->errors();
|
||||
}
|
||||
],
|
||||
|
|
|
@ -6,6 +6,7 @@ use Kirby\Toolkit\I18n;
|
|||
|
||||
return [
|
||||
'mixins' => [
|
||||
'batch',
|
||||
'details',
|
||||
'empty',
|
||||
'headline',
|
||||
|
@ -90,14 +91,15 @@ return [
|
|||
$files = $files->flip();
|
||||
}
|
||||
|
||||
return $files;
|
||||
},
|
||||
'modelsPaginated' => function () {
|
||||
// apply the default pagination
|
||||
$files = $files->paginate([
|
||||
return $this->models()->paginate([
|
||||
'page' => $this->page,
|
||||
'limit' => $this->limit,
|
||||
'method' => 'none' // the page is manually provided
|
||||
]);
|
||||
|
||||
return $files;
|
||||
},
|
||||
'files' => function () {
|
||||
return $this->models;
|
||||
|
@ -105,15 +107,16 @@ return [
|
|||
'data' => function () {
|
||||
$data = [];
|
||||
|
||||
// the drag text needs to be absolute when the files come from
|
||||
// a different parent model
|
||||
$dragTextAbsolute = $this->model->is($this->parent) === false;
|
||||
|
||||
foreach ($this->models as $file) {
|
||||
$panel = $file->panel();
|
||||
foreach ($this->modelsPaginated() as $file) {
|
||||
$panel = $file->panel();
|
||||
$permissions = $file->permissions();
|
||||
|
||||
$item = [
|
||||
'dragText' => $panel->dragText('auto', $dragTextAbsolute),
|
||||
'dragText' => $panel->dragText(
|
||||
// the drag text needs to be absolute
|
||||
// when the files come from a different parent model
|
||||
absolute: $this->model->is($this->parent) === false
|
||||
),
|
||||
'extension' => $file->extension(),
|
||||
'filename' => $file->filename(),
|
||||
'id' => $file->id(),
|
||||
|
@ -125,6 +128,10 @@ return [
|
|||
'link' => $panel->url(true),
|
||||
'mime' => $file->mime(),
|
||||
'parent' => $file->parent()->panel()->path(),
|
||||
'permissions' => [
|
||||
'delete' => $permissions->can('delete'),
|
||||
'sort' => $permissions->can('sort'),
|
||||
],
|
||||
'template' => $file->template(),
|
||||
'text' => $file->toSafeString($this->text),
|
||||
'url' => $file->url(),
|
||||
|
@ -140,7 +147,7 @@ return [
|
|||
return $data;
|
||||
},
|
||||
'total' => function () {
|
||||
return $this->models->pagination()->total();
|
||||
return $this->models()->count();
|
||||
},
|
||||
'errors' => function () {
|
||||
$errors = [];
|
||||
|
@ -179,14 +186,8 @@ return [
|
|||
}
|
||||
|
||||
// count all uploaded files
|
||||
$max = $this->max ? $this->max - $this->total : null;
|
||||
|
||||
if ($this->max && $this->total === $this->max - 1) {
|
||||
$multiple = false;
|
||||
} else {
|
||||
$multiple = true;
|
||||
}
|
||||
|
||||
$max = $this->max ? $this->max - $this->total : null;
|
||||
$multiple = !$max || $max > 1;
|
||||
$template = $this->template === 'default' ? null : $this->template;
|
||||
|
||||
return [
|
||||
|
@ -220,6 +221,15 @@ return [
|
|||
|
||||
return true;
|
||||
}
|
||||
],
|
||||
[
|
||||
'pattern' => 'delete',
|
||||
'method' => 'DELETE',
|
||||
'action' => function () {
|
||||
return $this->section()->deleteSelected(
|
||||
ids: $this->requestBody('ids'),
|
||||
);
|
||||
}
|
||||
]
|
||||
];
|
||||
},
|
||||
|
@ -231,6 +241,7 @@ return [
|
|||
'options' => [
|
||||
'accept' => $this->accept,
|
||||
'apiUrl' => $this->parent->apiUrl(true) . '/sections/' . $this->name,
|
||||
'batch' => $this->batch,
|
||||
'columns' => $this->columnsWithTypes(),
|
||||
'empty' => $this->empty,
|
||||
'headline' => $this->headline,
|
||||
|
|
45
kirby/config/sections/mixins/batch.php
Normal file
45
kirby/config/sections/mixins/batch.php
Normal file
|
@ -0,0 +1,45 @@
|
|||
<?php
|
||||
|
||||
use Kirby\Exception\Exception;
|
||||
use Kirby\Exception\PermissionException;
|
||||
use Kirby\Toolkit\I18n;
|
||||
|
||||
return [
|
||||
'props' => [
|
||||
/**
|
||||
* Activates the batch delete option for the section
|
||||
*/
|
||||
'batch' => function (bool $batch = false) {
|
||||
return $batch;
|
||||
},
|
||||
],
|
||||
'methods' => [
|
||||
'deleteSelected' => function (array $ids): bool {
|
||||
if ($ids === []) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// check if batch deletion is allowed
|
||||
if ($this->batch() === false) {
|
||||
throw new PermissionException(
|
||||
message: 'The section does not support batch actions'
|
||||
);
|
||||
}
|
||||
|
||||
$min = $this->min();
|
||||
|
||||
// check if the section has enough items after the deletion
|
||||
if ($this->total() - count($ids) < $min) {
|
||||
throw new Exception(
|
||||
message: I18n::template('error.section.' . $this->type() . '.min.' . I18n::form($min), [
|
||||
'min' => $min,
|
||||
'section' => $this->headline()
|
||||
])
|
||||
);
|
||||
}
|
||||
|
||||
$this->models()->delete($ids);
|
||||
return true;
|
||||
}
|
||||
]
|
||||
];
|
|
@ -19,7 +19,7 @@ return [
|
|||
*/
|
||||
'layout' => function (string $layout = 'list') {
|
||||
$layouts = ['list', 'cardlets', 'cards', 'table'];
|
||||
return in_array($layout, $layouts) ? $layout : 'list';
|
||||
return in_array($layout, $layouts, true) ? $layout : 'list';
|
||||
},
|
||||
/**
|
||||
* Whether the raw content file values should be used for the table column previews. Should not be used unless it eases performance issues in your setup introduced with Kirby 4.2
|
||||
|
|
|
@ -24,7 +24,9 @@ return [
|
|||
$parent = $this->model->query($query);
|
||||
|
||||
if (!$parent) {
|
||||
throw new Exception('The parent for the query "' . $query . '" cannot be found in the section "' . $this->name() . '"');
|
||||
throw new Exception(
|
||||
message: 'The parent for the query "' . $query . '" cannot be found in the section "' . $this->name() . '"'
|
||||
);
|
||||
}
|
||||
|
||||
if (
|
||||
|
@ -33,7 +35,9 @@ return [
|
|||
$parent instanceof File === false &&
|
||||
$parent instanceof User === false
|
||||
) {
|
||||
throw new Exception('The parent for the section "' . $this->name() . '" has to be a page, site or user object');
|
||||
throw new Exception(
|
||||
message: 'The parent for the section "' . $this->name() . '" has to be a page, site or user object'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ return [
|
|||
|
||||
if (
|
||||
$this->type === 'pages' &&
|
||||
in_array($this->status, ['listed', 'published', 'all']) === false
|
||||
in_array($this->status, ['listed', 'published', 'all'], true) === false
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ use Kirby\Toolkit\I18n;
|
|||
|
||||
return [
|
||||
'mixins' => [
|
||||
'batch',
|
||||
'details',
|
||||
'empty',
|
||||
'headline',
|
||||
|
@ -44,7 +45,7 @@ return [
|
|||
$status = 'draft';
|
||||
}
|
||||
|
||||
if (in_array($status, ['all', 'draft', 'published', 'listed', 'unlisted']) === false) {
|
||||
if (in_array($status, ['all', 'draft', 'published', 'listed', 'unlisted'], true) === false) {
|
||||
$status = 'all';
|
||||
}
|
||||
|
||||
|
@ -77,7 +78,9 @@ return [
|
|||
$parent instanceof Site === false &&
|
||||
$parent instanceof Page === false
|
||||
) {
|
||||
throw new InvalidArgumentException('The parent is invalid. You must choose the site or a page as parent.');
|
||||
throw new InvalidArgumentException(
|
||||
message: 'The parent is invalid. You must choose the site or a page as parent.'
|
||||
);
|
||||
}
|
||||
|
||||
return $parent;
|
||||
|
@ -111,7 +114,7 @@ return [
|
|||
// filter by all set templates
|
||||
if (
|
||||
$this->templates &&
|
||||
in_array($intendedTemplate, $this->templates) === false
|
||||
in_array($intendedTemplate, $this->templates, true) === false
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
@ -119,7 +122,7 @@ return [
|
|||
// exclude by all ignored templates
|
||||
if (
|
||||
$this->templatesIgnore &&
|
||||
in_array($intendedTemplate, $this->templatesIgnore) === true
|
||||
in_array($intendedTemplate, $this->templatesIgnore, true) === true
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
@ -147,25 +150,26 @@ return [
|
|||
$pages = $pages->flip();
|
||||
}
|
||||
|
||||
return $pages;
|
||||
},
|
||||
'modelsPaginated' => function () {
|
||||
// pagination
|
||||
$pages = $pages->paginate([
|
||||
return $this->models()->paginate([
|
||||
'page' => $this->page,
|
||||
'limit' => $this->limit,
|
||||
'method' => 'none' // the page is manually provided
|
||||
]);
|
||||
|
||||
return $pages;
|
||||
},
|
||||
'pages' => function () {
|
||||
return $this->models;
|
||||
},
|
||||
'total' => function () {
|
||||
return $this->models->pagination()->total();
|
||||
return $this->models()->count();
|
||||
},
|
||||
'data' => function () {
|
||||
$data = [];
|
||||
|
||||
foreach ($this->models as $page) {
|
||||
foreach ($this->modelsPaginated() as $page) {
|
||||
$panel = $page->panel();
|
||||
$permissions = $page->permissions();
|
||||
|
||||
|
@ -180,10 +184,11 @@ return [
|
|||
'link' => $panel->url(true),
|
||||
'parent' => $page->parentId(),
|
||||
'permissions' => [
|
||||
'sort' => $permissions->can('sort'),
|
||||
'delete' => $permissions->can('delete'),
|
||||
'changeSlug' => $permissions->can('changeSlug'),
|
||||
'changeStatus' => $permissions->can('changeStatus'),
|
||||
'changeTitle' => $permissions->can('changeTitle'),
|
||||
'sort' => $permissions->can('sort'),
|
||||
],
|
||||
'status' => $page->status(),
|
||||
'template' => $page->intendedTemplate()->name(),
|
||||
|
@ -313,12 +318,28 @@ return [
|
|||
return $blueprints;
|
||||
},
|
||||
],
|
||||
// @codeCoverageIgnoreStart
|
||||
'api' => function () {
|
||||
return [
|
||||
[
|
||||
'pattern' => 'delete',
|
||||
'method' => 'DELETE',
|
||||
'action' => function () {
|
||||
return $this->section()->deleteSelected(
|
||||
ids: $this->requestBody('ids'),
|
||||
);
|
||||
}
|
||||
]
|
||||
];
|
||||
},
|
||||
// @codeCoverageIgnoreEnd
|
||||
'toArray' => function () {
|
||||
return [
|
||||
'data' => $this->data,
|
||||
'errors' => $this->errors,
|
||||
'options' => [
|
||||
'add' => $this->add,
|
||||
'batch' => $this->batch,
|
||||
'columns' => $this->columnsWithTypes(),
|
||||
'empty' => $this->empty,
|
||||
'headline' => $this->headline,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue