Upgrade to 3.7.0
This commit is contained in:
0
kirby/config/sections/fields.php
Normal file → Executable file
0
kirby/config/sections/fields.php
Normal file → Executable file
85
kirby/config/sections/files.php
Normal file → Executable file
85
kirby/config/sections/files.php
Normal file → Executable file
@@ -5,6 +5,7 @@ use Kirby\Toolkit\I18n;
|
||||
|
||||
return [
|
||||
'mixins' => [
|
||||
'details',
|
||||
'empty',
|
||||
'headline',
|
||||
'help',
|
||||
@@ -13,44 +14,10 @@ return [
|
||||
'max',
|
||||
'pagination',
|
||||
'parent',
|
||||
'search',
|
||||
'sort'
|
||||
],
|
||||
'props' => [
|
||||
/**
|
||||
* Enables/disables reverse sorting
|
||||
*/
|
||||
'flip' => function (bool $flip = false) {
|
||||
return $flip;
|
||||
},
|
||||
/**
|
||||
* Image options to control the source and look of file previews
|
||||
*/
|
||||
'image' => function ($image = null) {
|
||||
return $image ?? [];
|
||||
},
|
||||
/**
|
||||
* Optional info text setup. Info text is shown on the right (lists, cardlets) or below (cards) the filename.
|
||||
*/
|
||||
'info' => function ($info = null) {
|
||||
return I18n::translate($info, $info);
|
||||
},
|
||||
/**
|
||||
* 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`
|
||||
*/
|
||||
'size' => function (string $size = 'auto') {
|
||||
return $size;
|
||||
},
|
||||
/**
|
||||
* 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. `filename desc`)
|
||||
*/
|
||||
'sortBy' => function (string $sortBy = null) {
|
||||
return $sortBy;
|
||||
},
|
||||
/**
|
||||
* Filters all files by template and also sets the template, which will be used for all uploads
|
||||
*/
|
||||
@@ -87,6 +54,12 @@ return [
|
||||
// filter out all protected files
|
||||
$files = $files->filter('isReadable', true);
|
||||
|
||||
// search
|
||||
if ($this->search === true && empty($this->searchterm) === false) {
|
||||
$files = $files->search($this->searchterm);
|
||||
}
|
||||
|
||||
// sort
|
||||
if ($this->sortBy) {
|
||||
$files = $files->sort(...$files::sortArgs($this->sortBy));
|
||||
} else {
|
||||
@@ -117,12 +90,15 @@ return [
|
||||
foreach ($this->files as $file) {
|
||||
$panel = $file->panel();
|
||||
|
||||
$data[] = [
|
||||
$item = [
|
||||
'dragText' => $panel->dragText('auto', $dragTextAbsolute),
|
||||
'extension' => $file->extension(),
|
||||
'filename' => $file->filename(),
|
||||
'id' => $file->id(),
|
||||
'image' => $panel->image($this->image, $this->layout),
|
||||
'image' => $panel->image(
|
||||
$this->image,
|
||||
$this->layout === 'table' ? 'list' : $this->layout
|
||||
),
|
||||
'info' => $file->toSafeString($this->info ?? false),
|
||||
'link' => $panel->url(true),
|
||||
'mime' => $file->mime(),
|
||||
@@ -131,6 +107,12 @@ return [
|
||||
'text' => $file->toSafeString($this->text),
|
||||
'url' => $file->url(),
|
||||
];
|
||||
|
||||
if ($this->layout === 'table') {
|
||||
$item = $this->columnsValues($item, $file);
|
||||
}
|
||||
|
||||
$data[] = $item;
|
||||
}
|
||||
|
||||
return $data;
|
||||
@@ -166,32 +148,9 @@ return [
|
||||
]
|
||||
];
|
||||
},
|
||||
'link' => function () {
|
||||
$modelLink = $this->model->panel()->url(true);
|
||||
$parentLink = $this->parent->panel()->url(true);
|
||||
|
||||
if ($modelLink !== $parentLink) {
|
||||
return $parentLink;
|
||||
}
|
||||
},
|
||||
'pagination' => function () {
|
||||
return $this->pagination();
|
||||
},
|
||||
'sortable' => function () {
|
||||
if ($this->sortable === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($this->sortBy !== null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($this->flip === true) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
},
|
||||
'upload' => function () {
|
||||
if ($this->isFull() === true) {
|
||||
return false;
|
||||
@@ -228,13 +187,15 @@ return [
|
||||
'options' => [
|
||||
'accept' => $this->accept,
|
||||
'apiUrl' => $this->parent->apiUrl(true),
|
||||
'columns' => $this->columns,
|
||||
'empty' => $this->empty,
|
||||
'headline' => $this->headline,
|
||||
'help' => $this->help,
|
||||
'layout' => $this->layout,
|
||||
'link' => $this->link,
|
||||
'link' => $this->link(),
|
||||
'max' => $this->max,
|
||||
'min' => $this->min,
|
||||
'search' => $this->search,
|
||||
'size' => $this->size,
|
||||
'sortable' => $this->sortable,
|
||||
'upload' => $this->upload
|
||||
|
0
kirby/config/sections/info.php
Normal file → Executable file
0
kirby/config/sections/info.php
Normal file → Executable file
36
kirby/config/sections/mixins/details.php
Executable file
36
kirby/config/sections/mixins/details.php
Executable 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;
|
||||
}
|
||||
}
|
||||
]
|
||||
];
|
0
kirby/config/sections/mixins/empty.php
Normal file → Executable file
0
kirby/config/sections/mixins/empty.php
Normal file → Executable file
12
kirby/config/sections/mixins/headline.php
Normal file → Executable file
12
kirby/config/sections/mixins/headline.php
Normal file → Executable file
@@ -1,18 +1,26 @@
|
||||
<?php
|
||||
|
||||
use Kirby\Cms\Helpers;
|
||||
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.
|
||||
* @todo deprecate in 3.7
|
||||
* @todo remove in 3.9.0
|
||||
*/
|
||||
'headline' => function ($headline = null) {
|
||||
// TODO: add deprecation notive in 3.8.0
|
||||
// if ($headline !== null) {
|
||||
// Helpers::deprecated('`headline` prop for sections has been deprecated and will be removed in Kirby 3.9.0. Use `label` instead.');
|
||||
// }
|
||||
|
||||
return I18n::translate($headline, $headline);
|
||||
},
|
||||
/**
|
||||
* label is the new official replacement for 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);
|
||||
|
0
kirby/config/sections/mixins/help.php
Normal file → Executable file
0
kirby/config/sections/mixins/help.php
Normal file → Executable file
117
kirby/config/sections/mixins/layout.php
Normal file → Executable file
117
kirby/config/sections/mixins/layout.php
Normal file → Executable file
@@ -1,14 +1,125 @@
|
||||
<?php
|
||||
|
||||
use Kirby\Toolkit\I18n;
|
||||
use Kirby\Toolkit\Str;
|
||||
|
||||
return [
|
||||
'props' => [
|
||||
/**
|
||||
* Columns config for `layout: table`
|
||||
*/
|
||||
'columns' => function (array $columns = null) {
|
||||
return $columns ?? [];
|
||||
},
|
||||
/**
|
||||
* Section layout.
|
||||
* Available layout methods: `list`, `cardlets`, `cards`.
|
||||
* Available layout methods: `list`, `cardlets`, `cards`, `table`.
|
||||
*/
|
||||
'layout' => function (string $layout = 'list') {
|
||||
$layouts = ['list', 'cardlets', 'cards'];
|
||||
$layouts = ['list', 'cardlets', 'cards', 'table'];
|
||||
return in_array($layout, $layouts) ? $layout : 'list';
|
||||
},
|
||||
/**
|
||||
* 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`
|
||||
*/
|
||||
'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 with a key that won't
|
||||
// override the system columns
|
||||
$columns[$columnName . 'Cell'] = $column;
|
||||
}
|
||||
|
||||
if ($this->type === 'pages') {
|
||||
$columns['flag'] = [
|
||||
'label' => ' ',
|
||||
'mobile' => true,
|
||||
'type' => 'flag',
|
||||
'width' => 'var(--table-row-height)',
|
||||
];
|
||||
}
|
||||
|
||||
return $columns;
|
||||
},
|
||||
],
|
||||
'methods' => [
|
||||
'columnsValues' => function (array $item, $model) {
|
||||
$item['title'] = [
|
||||
'text' => $item['text'],
|
||||
'href' => $model->panel()->url(true)
|
||||
];
|
||||
|
||||
foreach ($this->columns as $columnName => $column) {
|
||||
// don't overwrite essential columns
|
||||
if (isset($item[$columnName]) === true) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (empty($column['value']) === false) {
|
||||
if ($column['type'] ?? false === 'html') {
|
||||
$value = $model->toString($column['value']);
|
||||
} else {
|
||||
$value = $model->toSafeString($column['value']);
|
||||
}
|
||||
} else {
|
||||
$value = $model->content()->get($column['id'] ?? $columnName)->value();
|
||||
}
|
||||
|
||||
$item[$columnName] = $value;
|
||||
}
|
||||
|
||||
return $item;
|
||||
}
|
||||
]
|
||||
],
|
||||
];
|
||||
|
0
kirby/config/sections/mixins/max.php
Normal file → Executable file
0
kirby/config/sections/mixins/max.php
Normal file → Executable file
0
kirby/config/sections/mixins/min.php
Normal file → Executable file
0
kirby/config/sections/mixins/min.php
Normal file → Executable file
5
kirby/config/sections/mixins/pagination.php
Normal file → Executable file
5
kirby/config/sections/mixins/pagination.php
Normal file → Executable file
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
|
||||
use Kirby\Cms\App;
|
||||
use Kirby\Toolkit\Pagination;
|
||||
|
||||
return [
|
||||
@@ -14,7 +15,7 @@ return [
|
||||
* Sets the default page for the pagination. This will overwrite default pagination.
|
||||
*/
|
||||
'page' => function (int $page = null) {
|
||||
return get('page', $page);
|
||||
return App::instance()->request()->get('page', $page);
|
||||
},
|
||||
],
|
||||
'methods' => [
|
||||
@@ -31,6 +32,6 @@ return [
|
||||
'page' => $pagination->page(),
|
||||
'total' => $pagination->total(),
|
||||
];
|
||||
},
|
||||
}
|
||||
]
|
||||
];
|
||||
|
0
kirby/config/sections/mixins/parent.php
Normal file → Executable file
0
kirby/config/sections/mixins/parent.php
Normal file → Executable file
19
kirby/config/sections/mixins/search.php
Executable file
19
kirby/config/sections/mixins/search.php
Executable file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
use Kirby\Cms\App;
|
||||
|
||||
return [
|
||||
'props' => [
|
||||
/**
|
||||
* Enable/disable the search in the sections
|
||||
*/
|
||||
'search' => function (bool $search = false): bool {
|
||||
return $search;
|
||||
}
|
||||
],
|
||||
'computed' => [
|
||||
'searchterm' => function (): ?string {
|
||||
return App::instance()->request()->get('searchterm');
|
||||
}
|
||||
]
|
||||
];
|
53
kirby/config/sections/mixins/sort.php
Executable file
53
kirby/config/sections/mixins/sort.php
Executable file
@@ -0,0 +1,53 @@
|
||||
<?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 $sortBy = null) {
|
||||
return $sortBy;
|
||||
},
|
||||
],
|
||||
'computed' => [
|
||||
'sortable' => function () {
|
||||
if ($this->sortable === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (
|
||||
$this->type === 'pages' &&
|
||||
in_array($this->status, ['listed', 'published', 'all']) === false
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// don't allow sorting while search filter is active
|
||||
if (empty($this->query) === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($this->sortBy !== null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($this->flip === true) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
]
|
||||
];
|
136
kirby/config/sections/pages.php
Normal file → Executable file
136
kirby/config/sections/pages.php
Normal file → Executable file
@@ -7,6 +7,7 @@ use Kirby\Toolkit\I18n;
|
||||
|
||||
return [
|
||||
'mixins' => [
|
||||
'details',
|
||||
'empty',
|
||||
'headline',
|
||||
'help',
|
||||
@@ -14,7 +15,9 @@ return [
|
||||
'min',
|
||||
'max',
|
||||
'pagination',
|
||||
'parent'
|
||||
'parent',
|
||||
'search',
|
||||
'sort'
|
||||
],
|
||||
'props' => [
|
||||
/**
|
||||
@@ -24,42 +27,6 @@ return [
|
||||
'create' => function ($create = null) {
|
||||
return $create;
|
||||
},
|
||||
/**
|
||||
* Enables/disables reverse sorting
|
||||
*/
|
||||
'flip' => function (bool $flip = false) {
|
||||
return $flip;
|
||||
},
|
||||
/**
|
||||
* Image options to control the source and look of page previews
|
||||
*/
|
||||
'image' => function ($image = null) {
|
||||
return $image ?? [];
|
||||
},
|
||||
/**
|
||||
* Optional info text setup. Info text is shown on the right (lists) or below (cards) the page title.
|
||||
*/
|
||||
'info' => function ($info = null) {
|
||||
return I18n::translate($info, $info);
|
||||
},
|
||||
/**
|
||||
* 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`
|
||||
*/
|
||||
'size' => function (string $size = 'auto') {
|
||||
return $size;
|
||||
},
|
||||
/**
|
||||
* 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 $sortBy = null) {
|
||||
return $sortBy;
|
||||
},
|
||||
/**
|
||||
* Filters pages by their status. Available status settings: `draft`, `unlisted`, `listed`, `published`, `all`.
|
||||
*/
|
||||
@@ -79,19 +46,16 @@ return [
|
||||
*/
|
||||
'templates' => function ($templates = null) {
|
||||
return A::wrap($templates ?? $this->template);
|
||||
},
|
||||
/**
|
||||
* Setup for the main text in the list or cards. By default this will display the page title.
|
||||
*/
|
||||
'text' => function ($text = '{{ page.title }}') {
|
||||
return I18n::translate($text, $text);
|
||||
}
|
||||
],
|
||||
'computed' => [
|
||||
'parent' => function () {
|
||||
$parent = $this->parentModel();
|
||||
|
||||
if (is_a($parent, 'Kirby\Cms\Site') === false && is_a($parent, 'Kirby\Cms\Page') === false) {
|
||||
if (
|
||||
is_a($parent, 'Kirby\Cms\Site') === false &&
|
||||
is_a($parent, 'Kirby\Cms\Page') === false
|
||||
) {
|
||||
throw new InvalidArgumentException('The parent is invalid. You must choose the site or a page as parent.');
|
||||
}
|
||||
|
||||
@@ -115,20 +79,28 @@ return [
|
||||
$pages = $this->parent->childrenAndDrafts();
|
||||
}
|
||||
|
||||
// loop for the best performance
|
||||
foreach ($pages->data as $id => $page) {
|
||||
|
||||
// filters pages that are protected and not in the templates list
|
||||
// internal `filter()` method used instead of foreach loop that previously included `unset()`
|
||||
// because `unset()` is updating the original data, `filter()` is just filtering
|
||||
// also it has been tested that there is no performance difference
|
||||
// even in 0.1 seconds on 100k virtual pages
|
||||
$pages = $pages->filter(function ($page) {
|
||||
// remove all protected pages
|
||||
if ($page->isReadable() === false) {
|
||||
unset($pages->data[$id]);
|
||||
continue;
|
||||
return false;
|
||||
}
|
||||
|
||||
// filter by all set templates
|
||||
if ($this->templates && in_array($page->intendedTemplate()->name(), $this->templates) === false) {
|
||||
unset($pages->data[$id]);
|
||||
continue;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
// search
|
||||
if ($this->search === true && empty($this->searchterm) === false) {
|
||||
$pages = $pages->search($this->searchterm);
|
||||
}
|
||||
|
||||
// sort
|
||||
@@ -156,27 +128,36 @@ return [
|
||||
'data' => function () {
|
||||
$data = [];
|
||||
|
||||
foreach ($this->pages as $item) {
|
||||
$panel = $item->panel();
|
||||
$permissions = $item->permissions();
|
||||
foreach ($this->pages as $page) {
|
||||
$panel = $page->panel();
|
||||
$permissions = $page->permissions();
|
||||
|
||||
$data[] = [
|
||||
$item = [
|
||||
'dragText' => $panel->dragText(),
|
||||
'id' => $item->id(),
|
||||
'image' => $panel->image($this->image, $this->layout),
|
||||
'info' => $item->toSafeString($this->info ?? false),
|
||||
'id' => $page->id(),
|
||||
'image' => $panel->image(
|
||||
$this->image,
|
||||
$this->layout === 'table' ? 'list' : $this->layout
|
||||
),
|
||||
'info' => $page->toSafeString($this->info ?? false),
|
||||
'link' => $panel->url(true),
|
||||
'parent' => $item->parentId(),
|
||||
'parent' => $page->parentId(),
|
||||
'permissions' => [
|
||||
'sort' => $permissions->can('sort'),
|
||||
'changeSlug' => $permissions->can('changeSlug'),
|
||||
'changeStatus' => $permissions->can('changeStatus'),
|
||||
'changeTitle' => $permissions->can('changeTitle'),
|
||||
],
|
||||
'status' => $item->status(),
|
||||
'template' => $item->intendedTemplate()->name(),
|
||||
'text' => $item->toSafeString($this->text),
|
||||
'status' => $page->status(),
|
||||
'template' => $page->intendedTemplate()->name(),
|
||||
'text' => $page->toSafeString($this->text),
|
||||
];
|
||||
|
||||
if ($this->layout === 'table') {
|
||||
$item = $this->columnsValues($item, $page);
|
||||
}
|
||||
|
||||
$data[] = $item;
|
||||
}
|
||||
|
||||
return $data;
|
||||
@@ -224,35 +205,8 @@ return [
|
||||
|
||||
return true;
|
||||
},
|
||||
'link' => function () {
|
||||
$modelLink = $this->model->panel()->url(true);
|
||||
$parentLink = $this->parent->panel()->url(true);
|
||||
|
||||
if ($modelLink !== $parentLink) {
|
||||
return $parentLink;
|
||||
}
|
||||
},
|
||||
'pagination' => function () {
|
||||
return $this->pagination();
|
||||
},
|
||||
'sortable' => function () {
|
||||
if (in_array($this->status, ['listed', 'published', 'all']) === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($this->sortable === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($this->sortBy !== null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($this->flip === true) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
],
|
||||
'methods' => [
|
||||
@@ -291,13 +245,15 @@ return [
|
||||
'errors' => $this->errors,
|
||||
'options' => [
|
||||
'add' => $this->add,
|
||||
'columns' => $this->columns,
|
||||
'empty' => $this->empty,
|
||||
'headline' => $this->headline,
|
||||
'help' => $this->help,
|
||||
'layout' => $this->layout,
|
||||
'link' => $this->link,
|
||||
'link' => $this->link(),
|
||||
'max' => $this->max,
|
||||
'min' => $this->min,
|
||||
'search' => $this->search,
|
||||
'size' => $this->size,
|
||||
'sortable' => $this->sortable
|
||||
],
|
||||
|
62
kirby/config/sections/stats.php
Executable file
62
kirby/config/sections/stats.php
Executable file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
use Kirby\Toolkit\I18n;
|
||||
|
||||
return [
|
||||
'mixins' => [
|
||||
'headline',
|
||||
],
|
||||
'props' => [
|
||||
/**
|
||||
* Array or query string for reports. Each report needs a `label` and `value` and can have additional `info`, `link` and `theme` settings.
|
||||
*/
|
||||
'reports' => function ($reports = null) {
|
||||
if ($reports === null) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (is_string($reports) === true) {
|
||||
$reports = $this->model()->query($reports);
|
||||
}
|
||||
|
||||
if (is_array($reports) === false) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return $reports;
|
||||
},
|
||||
/**
|
||||
* The size of the report cards. Available sizes: `tiny`, `small`, `medium`, `large`
|
||||
*/
|
||||
'size' => function (string $size = 'large') {
|
||||
return $size;
|
||||
}
|
||||
],
|
||||
'computed' => [
|
||||
'reports' => function () {
|
||||
$reports = [];
|
||||
$model = $this->model();
|
||||
$value = fn ($value) => $value === null ? null : $model->toString($value);
|
||||
|
||||
foreach ($this->reports as $report) {
|
||||
if (is_string($report) === true) {
|
||||
$report = $model->query($report);
|
||||
}
|
||||
|
||||
if (is_array($report) === false) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$reports[] = [
|
||||
'label' => I18n::translate($report['label'], $report['label']),
|
||||
'value' => $value($report['value'] ?? null),
|
||||
'info' => $value($report['info'] ?? null),
|
||||
'link' => $value($report['link'] ?? null),
|
||||
'theme' => $value($report['theme'] ?? null)
|
||||
];
|
||||
}
|
||||
|
||||
return $reports;
|
||||
}
|
||||
]
|
||||
];
|
Reference in New Issue
Block a user