init with kirby, vue and pagedjs interactive
This commit is contained in:
commit
dc0ae26464
968 changed files with 211706 additions and 0 deletions
34
public/kirby/config/sections/fields.php
Normal file
34
public/kirby/config/sections/fields.php
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
use Kirby\Form\Form;
|
||||
|
||||
return [
|
||||
'props' => [
|
||||
'fields' => function (array $fields = []) {
|
||||
return $fields;
|
||||
}
|
||||
],
|
||||
'computed' => [
|
||||
'form' => function () {
|
||||
return new Form(
|
||||
fields: $this->fields,
|
||||
model: $this->model,
|
||||
language: 'current'
|
||||
);
|
||||
},
|
||||
'fields' => function () {
|
||||
return $this->form->fields()->toProps();
|
||||
}
|
||||
],
|
||||
'methods' => [
|
||||
'errors' => function () {
|
||||
$this->form->fill($this->model->content('current')->toArray());
|
||||
return $this->form->errors();
|
||||
}
|
||||
],
|
||||
'toArray' => function () {
|
||||
return [
|
||||
'fields' => $this->fields,
|
||||
];
|
||||
}
|
||||
];
|
||||
207
public/kirby/config/sections/files.php
Normal file
207
public/kirby/config/sections/files.php
Normal file
|
|
@ -0,0 +1,207 @@
|
|||
<?php
|
||||
|
||||
use Kirby\Cms\File;
|
||||
use Kirby\Panel\Collector\FilesCollector;
|
||||
use Kirby\Panel\Ui\Item\FileItem;
|
||||
use Kirby\Panel\Ui\Upload;
|
||||
use Kirby\Toolkit\I18n;
|
||||
|
||||
return [
|
||||
'mixins' => [
|
||||
'batch',
|
||||
'details',
|
||||
'empty',
|
||||
'headline',
|
||||
'help',
|
||||
'layout',
|
||||
'min',
|
||||
'max',
|
||||
'pagination',
|
||||
'parent',
|
||||
'search',
|
||||
'sort'
|
||||
],
|
||||
'props' => [
|
||||
/**
|
||||
* Filters pages by a query. Sorting will be disabled
|
||||
*/
|
||||
'query' => function (string|null $query = null) {
|
||||
return $query;
|
||||
},
|
||||
/**
|
||||
* Filters all files by template and also sets the template, which will be used for all uploads
|
||||
*/
|
||||
'template' => function (string|null $template = null) {
|
||||
return $template;
|
||||
},
|
||||
/**
|
||||
* Setup for the main text in the list or cards. By default this will display the filename.
|
||||
*/
|
||||
'text' => function ($text = '{{ file.filename }}') {
|
||||
return I18n::translate($text, $text);
|
||||
}
|
||||
],
|
||||
'computed' => [
|
||||
'accept' => function () {
|
||||
if ($this->template) {
|
||||
$file = new File([
|
||||
'filename' => 'tmp',
|
||||
'parent' => $this->model(),
|
||||
'template' => $this->template
|
||||
]);
|
||||
|
||||
return $file->blueprint()->acceptAttribute();
|
||||
}
|
||||
|
||||
return null;
|
||||
},
|
||||
'parent' => function () {
|
||||
return $this->parentModel();
|
||||
},
|
||||
'collector' => function () {
|
||||
return $this->collector ??= new FilesCollector(
|
||||
flip: $this->flip(),
|
||||
limit: $this->limit(),
|
||||
page: $this->page() ?? 1,
|
||||
parent: $this->parent(),
|
||||
query: $this->query(),
|
||||
search: $this->searchterm(),
|
||||
sortBy: $this->sortBy(),
|
||||
template: $this->template(),
|
||||
);
|
||||
},
|
||||
'models' => function () {
|
||||
return $this->collector()->models();
|
||||
},
|
||||
'modelsPaginated' => function () {
|
||||
return $this->collector()->models(paginated: true);
|
||||
},
|
||||
'files' => function () {
|
||||
return $this->models;
|
||||
},
|
||||
'data' => function () {
|
||||
$data = [];
|
||||
$dragTextIsAbsolute = $this->model->is($this->parent) === false;
|
||||
|
||||
foreach ($this->modelsPaginated() as $file) {
|
||||
$item = (new FileItem(
|
||||
file: $file,
|
||||
dragTextIsAbsolute: $dragTextIsAbsolute,
|
||||
image: $this->image,
|
||||
layout: $this->layout,
|
||||
info: $this->info,
|
||||
text: $this->text,
|
||||
))->props();
|
||||
|
||||
if ($this->layout === 'table') {
|
||||
$item = $this->columnsValues($item, $file);
|
||||
}
|
||||
|
||||
$data[] = $item;
|
||||
}
|
||||
|
||||
return $data;
|
||||
},
|
||||
'total' => function () {
|
||||
return $this->models()->count();
|
||||
},
|
||||
'errors' => function () {
|
||||
$errors = [];
|
||||
|
||||
if ($this->validateMax() === false) {
|
||||
$errors['max'] = I18n::template('error.section.files.max.' . I18n::form($this->max), [
|
||||
'max' => $this->max,
|
||||
'section' => $this->headline
|
||||
]);
|
||||
}
|
||||
|
||||
if ($this->validateMin() === false) {
|
||||
$errors['min'] = I18n::template('error.section.files.min.' . I18n::form($this->min), [
|
||||
'min' => $this->min,
|
||||
'section' => $this->headline
|
||||
]);
|
||||
}
|
||||
|
||||
if (empty($errors) === true) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return [
|
||||
$this->name => [
|
||||
'label' => $this->headline,
|
||||
'message' => $errors,
|
||||
]
|
||||
];
|
||||
},
|
||||
'pagination' => function () {
|
||||
return $this->pagination();
|
||||
},
|
||||
'upload' => function () {
|
||||
if ($this->isFull() === true) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$settings = new Upload(
|
||||
api: $this->parent->apiUrl(true) . '/files',
|
||||
accept: $this->accept,
|
||||
max: $this->max ? $this->max - $this->total : null,
|
||||
preview: $this->image,
|
||||
sort: $this->sortable === true ? $this->total + 1 : null,
|
||||
template: $this->template,
|
||||
);
|
||||
|
||||
return $settings->props();
|
||||
}
|
||||
],
|
||||
// @codeCoverageIgnoreStart
|
||||
'api' => function () {
|
||||
return [
|
||||
[
|
||||
'pattern' => 'sort',
|
||||
'method' => 'PATCH',
|
||||
'action' => function () {
|
||||
$this->section()->model()->files()->changeSort(
|
||||
$this->requestBody('files'),
|
||||
$this->requestBody('index')
|
||||
);
|
||||
|
||||
return true;
|
||||
}
|
||||
],
|
||||
[
|
||||
'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' => [
|
||||
'accept' => $this->accept,
|
||||
'apiUrl' => $this->parent->apiUrl(true) . '/sections/' . $this->name,
|
||||
'batch' => $this->batch,
|
||||
'columns' => $this->columnsWithTypes(),
|
||||
'empty' => $this->empty,
|
||||
'headline' => $this->headline,
|
||||
'help' => $this->help,
|
||||
'layout' => $this->layout,
|
||||
'link' => $this->link(),
|
||||
'max' => $this->max,
|
||||
'min' => $this->min,
|
||||
'search' => $this->search,
|
||||
'size' => $this->size,
|
||||
'sortable' => $this->sortable,
|
||||
'upload' => $this->upload
|
||||
],
|
||||
'pagination' => $this->pagination
|
||||
];
|
||||
}
|
||||
];
|
||||
37
public/kirby/config/sections/info.php
Normal file
37
public/kirby/config/sections/info.php
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
|
||||
use Kirby\Toolkit\I18n;
|
||||
|
||||
return [
|
||||
'mixins' => [
|
||||
'headline',
|
||||
],
|
||||
'props' => [
|
||||
'icon' => function (string|null $icon = null) {
|
||||
return $icon;
|
||||
},
|
||||
'text' => function ($text = null) {
|
||||
return I18n::translate($text, $text);
|
||||
},
|
||||
'theme' => function (string|null $theme = null) {
|
||||
return $theme;
|
||||
}
|
||||
],
|
||||
'computed' => [
|
||||
'text' => function () {
|
||||
if ($this->text) {
|
||||
$text = $this->model()->toSafeString($this->text);
|
||||
$text = $this->kirby()->kirbytext($text);
|
||||
return $text;
|
||||
}
|
||||
},
|
||||
],
|
||||
'toArray' => function () {
|
||||
return [
|
||||
'icon' => $this->icon,
|
||||
'label' => $this->headline,
|
||||
'text' => $this->text,
|
||||
'theme' => $this->theme
|
||||
];
|
||||
}
|
||||
];
|
||||
45
public/kirby/config/sections/mixins/batch.php
Normal file
45
public/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;
|
||||
}
|
||||
]
|
||||
];
|
||||
36
public/kirby/config/sections/mixins/details.php
Normal file
36
public/kirby/config/sections/mixins/details.php
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
use Kirby\Toolkit\I18n;
|
||||
|
||||
return [
|
||||
'props' => [
|
||||
/**
|
||||
* Image options to control the source and look of preview
|
||||
*/
|
||||
'image' => function ($image = null) {
|
||||
return $image ?? [];
|
||||
},
|
||||
/**
|
||||
* Optional info text setup. Info text is shown on the right (lists, cardlets) or below (cards) the title.
|
||||
*/
|
||||
'info' => function ($info = null) {
|
||||
return I18n::translate($info, $info);
|
||||
},
|
||||
/**
|
||||
* Setup for the main text in the list or cards. By default this will display the title.
|
||||
*/
|
||||
'text' => function ($text = '{{ model.title }}') {
|
||||
return I18n::translate($text, $text);
|
||||
}
|
||||
],
|
||||
'methods' => [
|
||||
'link' => function () {
|
||||
$modelLink = $this->model->panel()->url(true);
|
||||
$parentLink = $this->parent->panel()->url(true);
|
||||
|
||||
if ($modelLink !== $parentLink) {
|
||||
return $parentLink;
|
||||
}
|
||||
}
|
||||
]
|
||||
];
|
||||
21
public/kirby/config/sections/mixins/empty.php
Normal file
21
public/kirby/config/sections/mixins/empty.php
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
|
||||
use Kirby\Toolkit\I18n;
|
||||
|
||||
return [
|
||||
'props' => [
|
||||
/**
|
||||
* Sets the text for the empty state box
|
||||
*/
|
||||
'empty' => function ($empty = null) {
|
||||
return I18n::translate($empty, $empty);
|
||||
}
|
||||
],
|
||||
'computed' => [
|
||||
'empty' => function () {
|
||||
if ($this->empty) {
|
||||
return $this->model()->toSafeString($this->empty);
|
||||
}
|
||||
}
|
||||
]
|
||||
];
|
||||
36
public/kirby/config/sections/mixins/headline.php
Normal file
36
public/kirby/config/sections/mixins/headline.php
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
use Kirby\Toolkit\I18n;
|
||||
|
||||
return [
|
||||
'props' => [
|
||||
/**
|
||||
* The headline for the section. This can be a simple string or a template with additional info from the parent page.
|
||||
* @deprecated 3.8.0 Use `label` instead
|
||||
*/
|
||||
'headline' => function ($headline = null) {
|
||||
return I18n::translate($headline, $headline);
|
||||
},
|
||||
/**
|
||||
* The label for the section. This can be a simple string or
|
||||
* a template with additional info from the parent page.
|
||||
* Replaces the `headline` prop.
|
||||
*/
|
||||
'label' => function ($label = null) {
|
||||
return I18n::translate($label, $label);
|
||||
}
|
||||
],
|
||||
'computed' => [
|
||||
'headline' => function () {
|
||||
if ($this->label) {
|
||||
return $this->model()->toString($this->label);
|
||||
}
|
||||
|
||||
if ($this->headline) {
|
||||
return $this->model()->toString($this->headline);
|
||||
}
|
||||
|
||||
return ucfirst($this->name);
|
||||
}
|
||||
]
|
||||
];
|
||||
23
public/kirby/config/sections/mixins/help.php
Normal file
23
public/kirby/config/sections/mixins/help.php
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
use Kirby\Toolkit\I18n;
|
||||
|
||||
return [
|
||||
'props' => [
|
||||
/**
|
||||
* Sets the help text
|
||||
*/
|
||||
'help' => function ($help = null) {
|
||||
return I18n::translate($help, $help);
|
||||
}
|
||||
],
|
||||
'computed' => [
|
||||
'help' => function () {
|
||||
if ($this->help) {
|
||||
$help = $this->model()->toSafeString($this->help);
|
||||
$help = $this->kirby()->kirbytext($help);
|
||||
return $help;
|
||||
}
|
||||
}
|
||||
]
|
||||
];
|
||||
178
public/kirby/config/sections/mixins/layout.php
Normal file
178
public/kirby/config/sections/mixins/layout.php
Normal file
|
|
@ -0,0 +1,178 @@
|
|||
<?php
|
||||
|
||||
use Kirby\Cms\ModelWithContent;
|
||||
use Kirby\Form\Form;
|
||||
use Kirby\Toolkit\I18n;
|
||||
use Kirby\Toolkit\Str;
|
||||
|
||||
return [
|
||||
'props' => [
|
||||
/**
|
||||
* Columns config for `layout: table`
|
||||
*/
|
||||
'columns' => function (array|null $columns = null) {
|
||||
return $columns ?? [];
|
||||
},
|
||||
/**
|
||||
* Section layout.
|
||||
* Available layout methods: `list`, `cardlets`, `cards`, `table`.
|
||||
*/
|
||||
'layout' => function (string $layout = 'list') {
|
||||
$layouts = ['list', 'cardlets', 'cards', 'table'];
|
||||
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
|
||||
*
|
||||
* @todo remove when Form classes have been refactored
|
||||
*/
|
||||
'rawvalues' => function (bool $rawvalues = false) {
|
||||
return $rawvalues;
|
||||
},
|
||||
/**
|
||||
* The size option controls the size of cards. By default cards are auto-sized and the cards grid will always fill the full width. With a size you can disable auto-sizing. Available sizes: `tiny`, `small`, `medium`, `large`, `huge`, `full`
|
||||
*/
|
||||
'size' => function (string $size = 'auto') {
|
||||
return $size;
|
||||
},
|
||||
],
|
||||
'computed' => [
|
||||
'columns' => function () {
|
||||
$columns = [];
|
||||
|
||||
if ($this->layout !== 'table') {
|
||||
return [];
|
||||
}
|
||||
|
||||
if ($this->image !== false) {
|
||||
$columns['image'] = [
|
||||
'label' => ' ',
|
||||
'mobile' => true,
|
||||
'type' => 'image',
|
||||
'width' => 'var(--table-row-height)'
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->text) {
|
||||
$columns['title'] = [
|
||||
'label' => I18n::translate('title'),
|
||||
'mobile' => true,
|
||||
'type' => 'url',
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->info) {
|
||||
$columns['info'] = [
|
||||
'label' => I18n::translate('info'),
|
||||
'type' => 'text',
|
||||
];
|
||||
}
|
||||
|
||||
foreach ($this->columns as $columnName => $column) {
|
||||
if ($column === true) {
|
||||
$column = [];
|
||||
}
|
||||
|
||||
if ($column === false) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// fallback for labels
|
||||
$column['label'] ??= Str::ucfirst($columnName);
|
||||
|
||||
// make sure to translate labels
|
||||
$column['label'] = I18n::translate($column['label'], $column['label']);
|
||||
|
||||
// keep the original column name as id
|
||||
$column['id'] = $columnName;
|
||||
|
||||
// add the custom column to the array
|
||||
// allowing to extend/overwrite existing columns
|
||||
$columns[$columnName] = [
|
||||
...$columns[$columnName] ?? [],
|
||||
...$column
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->type === 'pages') {
|
||||
$columns['flag'] = [
|
||||
'label' => ' ',
|
||||
'mobile' => true,
|
||||
'type' => 'flag',
|
||||
'width' => 'var(--table-row-height)',
|
||||
];
|
||||
}
|
||||
|
||||
return $columns;
|
||||
},
|
||||
],
|
||||
'methods' => [
|
||||
'columnsWithTypes' => function () {
|
||||
$columns = $this->columns;
|
||||
|
||||
// add the type to the columns for the table layout
|
||||
if ($this->layout === 'table') {
|
||||
$blueprint = $this->models->first()?->blueprint();
|
||||
|
||||
if ($blueprint === null) {
|
||||
return $columns;
|
||||
}
|
||||
|
||||
foreach ($columns as $columnName => $column) {
|
||||
if ($id = $column['id'] ?? null) {
|
||||
$columns[$columnName]['type'] ??= $blueprint->field($id)['type'] ?? null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $columns;
|
||||
},
|
||||
'columnsValues' => function (array $item, ModelWithContent $model) {
|
||||
$item['title'] = [
|
||||
// override toSafeString() coming from `$item`
|
||||
// because the table cells don't use v-html
|
||||
'text' => $model->toString($this->text),
|
||||
'href' => $model->panel()->url(true)
|
||||
];
|
||||
|
||||
if ($this->info) {
|
||||
// override toSafeString() coming from `$item`
|
||||
// because the table cells don't use v-html
|
||||
$item['info'] = $model->toString($this->info);
|
||||
}
|
||||
|
||||
// if forcing raw values, get those directly from content file
|
||||
// TODO: remove once Form classes have been refactored
|
||||
// @codeCoverageIgnoreStart
|
||||
if ($this->rawvalues === true) {
|
||||
foreach ($this->columns as $columnName => $column) {
|
||||
$item[$columnName] = match (empty($column['value'])) {
|
||||
// if column value defined, resolve the query
|
||||
false => $model->toString($column['value']),
|
||||
// otherwise use the form value,
|
||||
// but don't overwrite columns
|
||||
default => $item[$columnName] ?? $model->content()->get($column['id'] ?? $columnName)->value()
|
||||
};
|
||||
}
|
||||
|
||||
return $item;
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
||||
// Use form to get the proper values for the columns
|
||||
$form = Form::for($model)->values();
|
||||
|
||||
foreach ($this->columns as $columnName => $column) {
|
||||
$item[$columnName] = match (empty($column['value'])) {
|
||||
// if column value defined, resolve the query
|
||||
false => $model->toString($column['value']),
|
||||
// otherwise use the form value,
|
||||
// but don't overwrite columns
|
||||
default => $item[$columnName] ?? $form[$column['id'] ?? $columnName] ?? null
|
||||
};
|
||||
}
|
||||
|
||||
return $item;
|
||||
}
|
||||
],
|
||||
];
|
||||
28
public/kirby/config/sections/mixins/max.php
Normal file
28
public/kirby/config/sections/mixins/max.php
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
'props' => [
|
||||
/**
|
||||
* Sets the maximum number of allowed entries in the section
|
||||
*/
|
||||
'max' => function (int|null $max = null) {
|
||||
return $max;
|
||||
}
|
||||
],
|
||||
'methods' => [
|
||||
'isFull' => function () {
|
||||
if ($this->max) {
|
||||
return $this->total >= $this->max;
|
||||
}
|
||||
|
||||
return false;
|
||||
},
|
||||
'validateMax' => function () {
|
||||
if ($this->max && $this->total > $this->max) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
]
|
||||
];
|
||||
21
public/kirby/config/sections/mixins/min.php
Normal file
21
public/kirby/config/sections/mixins/min.php
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
'props' => [
|
||||
/**
|
||||
* Sets the minimum number of required entries in the section
|
||||
*/
|
||||
'min' => function (int|null $min = null) {
|
||||
return $min;
|
||||
}
|
||||
],
|
||||
'methods' => [
|
||||
'validateMin' => function () {
|
||||
if ($this->min && $this->min > $this->total) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
]
|
||||
];
|
||||
37
public/kirby/config/sections/mixins/pagination.php
Normal file
37
public/kirby/config/sections/mixins/pagination.php
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
|
||||
use Kirby\Cms\App;
|
||||
use Kirby\Toolkit\Pagination;
|
||||
|
||||
return [
|
||||
'props' => [
|
||||
/**
|
||||
* Sets the number of items per page. If there are more items the pagination navigation will be shown at the bottom of the section.
|
||||
*/
|
||||
'limit' => function (int $limit = 20) {
|
||||
return $limit;
|
||||
},
|
||||
/**
|
||||
* Sets the default page for the pagination.
|
||||
*/
|
||||
'page' => function (int|null $page = null) {
|
||||
return App::instance()->request()->get('page', $page);
|
||||
},
|
||||
],
|
||||
'methods' => [
|
||||
'pagination' => function () {
|
||||
$pagination = new Pagination([
|
||||
'limit' => $this->limit,
|
||||
'page' => $this->page,
|
||||
'total' => $this->total
|
||||
]);
|
||||
|
||||
return [
|
||||
'limit' => $pagination->limit(),
|
||||
'offset' => $pagination->offset(),
|
||||
'page' => $pagination->page(),
|
||||
'total' => $pagination->total(),
|
||||
];
|
||||
}
|
||||
]
|
||||
];
|
||||
51
public/kirby/config/sections/mixins/parent.php
Normal file
51
public/kirby/config/sections/mixins/parent.php
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
<?php
|
||||
|
||||
use Kirby\Cms\File;
|
||||
use Kirby\Cms\Page;
|
||||
use Kirby\Cms\Site;
|
||||
use Kirby\Cms\User;
|
||||
use Kirby\Exception\Exception;
|
||||
|
||||
return [
|
||||
'props' => [
|
||||
/**
|
||||
* Sets the query to a parent to find items for the list
|
||||
*/
|
||||
'parent' => function (string|null $parent = null) {
|
||||
return $parent;
|
||||
}
|
||||
],
|
||||
'methods' => [
|
||||
'parentModel' => function () {
|
||||
$parent = $this->parent;
|
||||
|
||||
if (is_string($parent) === true) {
|
||||
$query = $parent;
|
||||
$parent = $this->model->query($query);
|
||||
|
||||
if (!$parent) {
|
||||
throw new Exception(
|
||||
message: 'The parent for the query "' . $query . '" cannot be found in the section "' . $this->name() . '"'
|
||||
);
|
||||
}
|
||||
|
||||
if (
|
||||
$parent instanceof Page === false &&
|
||||
$parent instanceof Site === false &&
|
||||
$parent instanceof File === false &&
|
||||
$parent instanceof User === false
|
||||
) {
|
||||
throw new Exception(
|
||||
message: 'The parent for the section "' . $this->name() . '" has to be a page, site or user object'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if ($parent === null) {
|
||||
return $this->model;
|
||||
}
|
||||
|
||||
return $parent;
|
||||
}
|
||||
]
|
||||
];
|
||||
23
public/kirby/config/sections/mixins/search.php
Normal file
23
public/kirby/config/sections/mixins/search.php
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
use Kirby\Cms\App;
|
||||
|
||||
return [
|
||||
'props' => [
|
||||
/**
|
||||
* Enable/disable the search in the sections
|
||||
*/
|
||||
'search' => function (bool $search = false): bool {
|
||||
return $search;
|
||||
}
|
||||
],
|
||||
'methods' => [
|
||||
'searchterm' => function (): string|null {
|
||||
if ($this->search() === true) {
|
||||
return App::instance()->request()->get('searchterm') ?? null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
]
|
||||
];
|
||||
57
public/kirby/config/sections/mixins/sort.php
Normal file
57
public/kirby/config/sections/mixins/sort.php
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
'props' => [
|
||||
/**
|
||||
* Enables/disables reverse sorting
|
||||
*/
|
||||
'flip' => function (bool $flip = false) {
|
||||
return $flip;
|
||||
},
|
||||
/**
|
||||
* Enables/disables manual sorting
|
||||
*/
|
||||
'sortable' => function (bool $sortable = true) {
|
||||
return $sortable;
|
||||
},
|
||||
/**
|
||||
* Overwrites manual sorting and sorts by the given field and sorting direction (i.e. `date desc`)
|
||||
*/
|
||||
'sortBy' => function (string|null $sortBy = null) {
|
||||
return $sortBy;
|
||||
},
|
||||
],
|
||||
'computed' => [
|
||||
'sortable' => function () {
|
||||
if ($this->sortable === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (
|
||||
$this->type === 'pages' &&
|
||||
in_array($this->status, ['listed', 'published', 'all'], true) === false
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// don't allow sorting while search filter is active
|
||||
if (empty($this->searchterm()) === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($this->query !== null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($this->sortBy !== null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($this->flip === true) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
]
|
||||
];
|
||||
288
public/kirby/config/sections/pages.php
Normal file
288
public/kirby/config/sections/pages.php
Normal file
|
|
@ -0,0 +1,288 @@
|
|||
<?php
|
||||
|
||||
use Kirby\Cms\Blueprint;
|
||||
use Kirby\Cms\Page;
|
||||
use Kirby\Cms\Pages;
|
||||
use Kirby\Cms\Site;
|
||||
use Kirby\Exception\InvalidArgumentException;
|
||||
use Kirby\Panel\Collector\PagesCollector;
|
||||
use Kirby\Panel\Ui\Item\PageItem;
|
||||
use Kirby\Toolkit\A;
|
||||
use Kirby\Toolkit\I18n;
|
||||
|
||||
return [
|
||||
'mixins' => [
|
||||
'batch',
|
||||
'details',
|
||||
'empty',
|
||||
'headline',
|
||||
'help',
|
||||
'layout',
|
||||
'min',
|
||||
'max',
|
||||
'pagination',
|
||||
'parent',
|
||||
'search',
|
||||
'sort'
|
||||
],
|
||||
'props' => [
|
||||
/**
|
||||
* Optional array of templates that should only be allowed to add
|
||||
* or `false` to completely disable page creation
|
||||
*/
|
||||
'create' => function ($create = null) {
|
||||
return $create;
|
||||
},
|
||||
/**
|
||||
* Filters pages by a query. Sorting will be disabled
|
||||
*/
|
||||
'query' => function (string|null $query = null) {
|
||||
return $query;
|
||||
},
|
||||
/**
|
||||
* Filters pages by their status. Available status settings: `draft`, `unlisted`, `listed`, `published`, `all`.
|
||||
*/
|
||||
'status' => function (string $status = '') {
|
||||
if ($status === 'drafts') {
|
||||
$status = 'draft';
|
||||
}
|
||||
|
||||
if (in_array($status, ['all', 'draft', 'published', 'listed', 'unlisted'], true) === false) {
|
||||
$status = 'all';
|
||||
}
|
||||
|
||||
return $status;
|
||||
},
|
||||
/**
|
||||
* Filters the list by single template.
|
||||
*/
|
||||
'template' => function (string|array|null $template = null) {
|
||||
return $template;
|
||||
},
|
||||
/**
|
||||
* Filters the list by templates and sets template options when adding new pages to the section.
|
||||
*/
|
||||
'templates' => function ($templates = null) {
|
||||
return A::wrap($templates ?? $this->template);
|
||||
},
|
||||
/**
|
||||
* Excludes the selected templates.
|
||||
*/
|
||||
'templatesIgnore' => function ($templates = null) {
|
||||
return A::wrap($templates);
|
||||
}
|
||||
],
|
||||
'computed' => [
|
||||
'parent' => function () {
|
||||
$parent = $this->parentModel();
|
||||
|
||||
if (
|
||||
$parent instanceof Site === false &&
|
||||
$parent instanceof Page === false
|
||||
) {
|
||||
throw new InvalidArgumentException(
|
||||
message: 'The parent is invalid. You must choose the site or a page as parent.'
|
||||
);
|
||||
}
|
||||
|
||||
return $parent;
|
||||
},
|
||||
'collector' => function () {
|
||||
return $this->collector ??= new PagesCollector(
|
||||
limit: $this->limit(),
|
||||
page: $this->page() ?? 1,
|
||||
parent: $this->parent(),
|
||||
query: $this->query(),
|
||||
status: $this->status(),
|
||||
templates: $this->templates(),
|
||||
templatesIgnore: $this->templatesIgnore(),
|
||||
search: $this->searchterm(),
|
||||
sortBy: $this->sortBy(),
|
||||
flip: $this->flip()
|
||||
);
|
||||
},
|
||||
'models' => function () {
|
||||
return $this->collector()->models();
|
||||
},
|
||||
'modelsPaginated' => function () {
|
||||
return $this->collector()->models(paginated: true);
|
||||
},
|
||||
'pages' => function () {
|
||||
return $this->models();
|
||||
},
|
||||
'total' => function () {
|
||||
return $this->models()->count();
|
||||
},
|
||||
'data' => function () {
|
||||
$data = [];
|
||||
|
||||
foreach ($this->modelsPaginated() as $page) {
|
||||
$item = (new PageItem(
|
||||
page: $page,
|
||||
image: $this->image,
|
||||
layout: $this->layout,
|
||||
info: $this->info,
|
||||
text: $this->text,
|
||||
))->props();
|
||||
|
||||
if ($this->layout === 'table') {
|
||||
$item = $this->columnsValues($item, $page);
|
||||
}
|
||||
|
||||
$data[] = $item;
|
||||
}
|
||||
|
||||
return $data;
|
||||
},
|
||||
'errors' => function () {
|
||||
$errors = [];
|
||||
|
||||
if ($this->validateMax() === false) {
|
||||
$errors['max'] = I18n::template('error.section.pages.max.' . I18n::form($this->max), [
|
||||
'max' => $this->max,
|
||||
'section' => $this->headline
|
||||
]);
|
||||
}
|
||||
|
||||
if ($this->validateMin() === false) {
|
||||
$errors['min'] = I18n::template('error.section.pages.min.' . I18n::form($this->min), [
|
||||
'min' => $this->min,
|
||||
'section' => $this->headline
|
||||
]);
|
||||
}
|
||||
|
||||
if (empty($errors) === true) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return [
|
||||
$this->name => [
|
||||
'label' => $this->headline,
|
||||
'message' => $errors,
|
||||
]
|
||||
];
|
||||
},
|
||||
'add' => function () {
|
||||
if ($this->create === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($this->isFull() === true) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// form here on, we need to check with which status
|
||||
// the pages are created and if the section can show
|
||||
// these newly created pages
|
||||
|
||||
// if the section shows pages no matter what status they have,
|
||||
// we can always show the add button
|
||||
if ($this->status === 'all') {
|
||||
return true;
|
||||
}
|
||||
|
||||
// collect all statuses of the blueprints
|
||||
// that are allowed to be created
|
||||
$statuses = [];
|
||||
|
||||
foreach ($this->blueprintNames() as $blueprint) {
|
||||
try {
|
||||
$props = Blueprint::load('pages/' . $blueprint);
|
||||
$statuses[] = $props['create']['status'] ?? 'draft';
|
||||
} catch (Throwable) {
|
||||
$statuses[] = 'draft'; // @codeCoverageIgnore
|
||||
}
|
||||
}
|
||||
|
||||
$statuses = array_unique($statuses);
|
||||
|
||||
// if there are multiple statuses or if the section is showing
|
||||
// a different status than new pages would be created with,
|
||||
// we cannot show the add button
|
||||
if (count($statuses) > 1 || $this->status !== $statuses[0]) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
},
|
||||
'pagination' => function () {
|
||||
return $this->pagination();
|
||||
}
|
||||
],
|
||||
'methods' => [
|
||||
'blueprints' => function () {
|
||||
$blueprints = [];
|
||||
|
||||
// convert every template to a usable option array
|
||||
// for the template select box
|
||||
foreach ($this->blueprintNames() as $blueprint) {
|
||||
try {
|
||||
$props = Blueprint::load('pages/' . $blueprint);
|
||||
|
||||
$blueprints[] = [
|
||||
'name' => basename($props['name']),
|
||||
'title' => $props['title'],
|
||||
];
|
||||
} catch (Throwable) {
|
||||
$blueprints[] = [
|
||||
'name' => basename($blueprint),
|
||||
'title' => ucfirst($blueprint),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return $blueprints;
|
||||
},
|
||||
'blueprintNames' => function () {
|
||||
$blueprints = empty($this->create) === false ? A::wrap($this->create) : $this->templates;
|
||||
|
||||
if (empty($blueprints) === true) {
|
||||
$blueprints = $this->kirby()->blueprints();
|
||||
}
|
||||
|
||||
// excludes ignored templates
|
||||
if ($templatesIgnore = $this->templatesIgnore) {
|
||||
$blueprints = array_diff($blueprints, $templatesIgnore);
|
||||
}
|
||||
|
||||
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,
|
||||
'help' => $this->help,
|
||||
'layout' => $this->layout,
|
||||
'link' => $this->link(),
|
||||
'max' => $this->max,
|
||||
'min' => $this->min,
|
||||
'search' => $this->search,
|
||||
'size' => $this->size,
|
||||
'sortable' => $this->sortable
|
||||
],
|
||||
'pagination' => $this->pagination,
|
||||
];
|
||||
}
|
||||
];
|
||||
38
public/kirby/config/sections/stats.php
Normal file
38
public/kirby/config/sections/stats.php
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
|
||||
use Kirby\Panel\Ui\Stats;
|
||||
|
||||
return [
|
||||
'mixins' => [
|
||||
'headline',
|
||||
],
|
||||
'props' => [
|
||||
/**
|
||||
* Array or query string for reports. Each report needs a `label` and `value` and can have additional `info`, `link`, `icon` and `theme` settings.
|
||||
*/
|
||||
'reports' => function (array|string|null $reports = null) {
|
||||
return $reports ?? [];
|
||||
},
|
||||
/**
|
||||
* The size of the report cards. Available sizes: `tiny`, `small`, `medium`, `large`
|
||||
*/
|
||||
'size' => function (string $size = 'large') {
|
||||
return $size;
|
||||
}
|
||||
],
|
||||
'computed' => [
|
||||
'stats' => function (): Stats {
|
||||
return $this->stats ??= Stats::from(
|
||||
model: $this->model(),
|
||||
reports: $this->reports(),
|
||||
size: $this->size()
|
||||
);
|
||||
},
|
||||
'reports' => function (): array {
|
||||
return $this->stats->reports();
|
||||
},
|
||||
'size' => function (): string {
|
||||
return $this->stats->size();
|
||||
}
|
||||
]
|
||||
];
|
||||
Loading…
Add table
Add a link
Reference in a new issue