1
0

downgrade to kirby v3

This commit is contained in:
Philip Wagner
2024-09-01 10:47:15 +02:00
parent a4b2aece7b
commit af86acb7a1
1085 changed files with 54743 additions and 65042 deletions

View File

@@ -1,7 +1,5 @@
<?php
use Kirby\Cms\Page;
use Kirby\Cms\Site;
use Kirby\Form\Form;
return [
@@ -33,10 +31,7 @@ return [
'fields' => function () {
$fields = $this->form->fields()->toArray();
if (
$this->model instanceof Page ||
$this->model instanceof Site
) {
if (is_a($this->model, 'Kirby\Cms\Page') === true || is_a($this->model, 'Kirby\Cms\Site') === true) {
// the title should never be updated directly via
// fields section to avoid conflicts with the rename dialog
unset($fields['title']);

View File

@@ -1,7 +1,6 @@
<?php
use Kirby\Cms\File;
use Kirby\Cms\Files;
use Kirby\Toolkit\I18n;
return [
@@ -19,12 +18,6 @@ return [
'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
*/
@@ -47,7 +40,7 @@ return [
'template' => $this->template
]);
return $file->blueprint()->acceptAttribute();
return $file->blueprint()->acceptMime();
}
return null;
@@ -55,27 +48,15 @@ return [
'parent' => function () {
return $this->parentModel();
},
'models' => function () {
if ($this->query !== null) {
$files = $this->parent->query($this->query, Files::class) ?? new Files([]);
} else {
$files = $this->parent->files();
}
'files' => function () {
$files = $this->parent->files()->template($this->template);
// filter files by template
$files = $files->template($this->template);
// filter out all protected and hidden files
$files = $files->filter('isListable', true);
// filter out all protected files
$files = $files->filter('isReadable', true);
// search
if ($this->search === true && empty($this->searchterm()) === false) {
$files = $files->search($this->searchterm());
// disable flip and sortBy while searching
// to show most relevant results
$this->flip = false;
$this->sortBy = null;
}
// sort
@@ -99,9 +80,6 @@ return [
return $files;
},
'files' => function () {
return $this->models;
},
'data' => function () {
$data = [];
@@ -109,7 +87,7 @@ return [
// a different parent model
$dragTextAbsolute = $this->model->is($this->parent) === false;
foreach ($this->models as $file) {
foreach ($this->files as $file) {
$panel = $file->panel();
$item = [
@@ -140,7 +118,7 @@ return [
return $data;
},
'total' => function () {
return $this->models->pagination()->total();
return $this->files->pagination()->total();
},
'errors' => function () {
$errors = [];
@@ -179,9 +157,10 @@ return [
}
// count all uploaded files
$max = $this->max ? $this->max - $this->total : null;
$total = count($this->data);
$max = $this->max ? $this->max - $total : null;
if ($this->max && $this->total === $this->max - 1) {
if ($this->max && $total === $this->max - 1) {
$multiple = false;
} else {
$multiple = true;
@@ -194,43 +173,21 @@ return [
'multiple' => $multiple,
'max' => $max,
'api' => $this->parent->apiUrl(true) . '/files',
'attributes' => [
// TODO: an edge issue that needs to be solved:
// if multiple users load the same section
// at the same time and upload a file,
// uploaded files have the same sort number
'sort' => $this->sortable === true ? $this->total + 1 : null,
'attributes' => array_filter([
'sort' => $this->sortable === true ? $total + 1 : null,
'template' => $template
]
])
];
}
],
// @codeCoverageIgnoreStart
'api' => function () {
return [
[
'pattern' => 'sort',
'method' => 'PATCH',
'action' => function () {
$this->section()->model()->files()->changeSort(
$this->requestBody('files'),
$this->requestBody('index')
);
return true;
}
]
];
},
// @codeCoverageIgnoreEnd
'toArray' => function () {
return [
'data' => $this->data,
'errors' => $this->errors,
'options' => [
'accept' => $this->accept,
'apiUrl' => $this->parent->apiUrl(true) . '/sections/' . $this->name,
'columns' => $this->columnsWithTypes(),
'apiUrl' => $this->parent->apiUrl(true),
'columns' => $this->columns,
'empty' => $this->empty,
'headline' => $this->headline,
'help' => $this->help,

View File

@@ -7,9 +7,6 @@ return [
'headline',
],
'props' => [
'icon' => function (string $icon = null) {
return $icon;
},
'text' => function ($text = null) {
return I18n::translate($text, $text);
},
@@ -28,10 +25,9 @@ return [
],
'toArray' => function () {
return [
'icon' => $this->icon,
'label' => $this->headline,
'text' => $this->text,
'theme' => $this->theme
'headline' => $this->headline,
'text' => $this->text,
'theme' => $this->theme
];
}
];

View File

@@ -1,14 +1,20 @@
<?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.
* @deprecated 3.8.0 Use `label` instead
* @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);
},
/**
@@ -22,14 +28,14 @@ return [
],
'computed' => [
'headline' => function () {
if ($this->label) {
return $this->model()->toString($this->label);
}
if ($this->headline) {
return $this->model()->toString($this->headline);
}
if ($this->label) {
return $this->model()->toString($this->label);
}
return ucfirst($this->name);
}
]

View File

@@ -1,7 +1,5 @@
<?php
use Kirby\Cms\ModelWithContent;
use Kirby\Form\Form;
use Kirby\Toolkit\I18n;
use Kirby\Toolkit\Str;
@@ -22,7 +20,7 @@ return [
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`, `full`
* 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;
@@ -30,7 +28,7 @@ return [
],
'computed' => [
'columns' => function () {
$columns = [];
$columns = [];
if ($this->layout !== 'table') {
return [];
@@ -78,12 +76,9 @@ return [
// 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
];
// 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') {
@@ -99,27 +94,7 @@ return [
},
],
'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) {
'columnsValues' => function (array $item, $model) {
$item['title'] = [
// override toSafeString() coming from `$item`
// because the table cells don't use v-html
@@ -133,20 +108,19 @@ return [
$item['info'] = $model->toString($this->info);
}
// 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,
};
// don't overwrite essential columns
if (isset($item[$columnName]) === true) {
continue;
}
if (empty($column['value']) === false) {
$value = $model->toString($column['value']);
} else {
$value = $model->content()->get($column['id'] ?? $columnName)->value();
}
$item[$columnName] = $value;
}
return $item;

View File

@@ -1,9 +1,5 @@
<?php
use Kirby\Cms\File;
use Kirby\Cms\Page;
use Kirby\Cms\Site;
use Kirby\Cms\User;
use Kirby\Exception\Exception;
return [
@@ -28,10 +24,10 @@ return [
}
if (
$parent instanceof Page === false &&
$parent instanceof Site === false &&
$parent instanceof File === false &&
$parent instanceof User === false
is_a($parent, 'Kirby\Cms\Page') === false &&
is_a($parent, 'Kirby\Cms\Site') === false &&
is_a($parent, 'Kirby\Cms\File') === false &&
is_a($parent, 'Kirby\Cms\User') === false
) {
throw new Exception('The parent for the section "' . $this->name() . '" has to be a page, site or user object');
}

View File

@@ -12,7 +12,7 @@ return [
}
],
'methods' => [
'searchterm' => function (): string|null {
'searchterm' => function (): ?string {
return App::instance()->request()->get('searchterm');
}
]

View File

@@ -39,10 +39,6 @@ return [
return false;
}
if ($this->query !== null) {
return false;
}
if ($this->sortBy !== null) {
return false;
}

View File

@@ -1,9 +1,6 @@
<?php
use Kirby\Cms\Blueprint;
use Kirby\Cms\Page;
use Kirby\Cms\Pages;
use Kirby\Cms\Site;
use Kirby\Exception\InvalidArgumentException;
use Kirby\Toolkit\A;
use Kirby\Toolkit\I18n;
@@ -30,12 +27,6 @@ return [
'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`.
*/
@@ -50,23 +41,11 @@ return [
return $status;
},
/**
* Filters the list by single template.
*/
'template' => function (string|array $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' => [
@@ -74,25 +53,30 @@ return [
$parent = $this->parentModel();
if (
$parent instanceof Site === false &&
$parent instanceof Page === false
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.');
}
return $parent;
},
'models' => function () {
if ($this->query !== null) {
$pages = $this->parent->query($this->query, Pages::class) ?? new Pages([]);
} else {
$pages = match ($this->status) {
'draft' => $this->parent->drafts(),
'listed' => $this->parent->children()->listed(),
'published' => $this->parent->children(),
'unlisted' => $this->parent->children()->unlisted(),
default => $this->parent->childrenAndDrafts()
};
'pages' => function () {
switch ($this->status) {
case 'draft':
$pages = $this->parent->drafts();
break;
case 'listed':
$pages = $this->parent->children()->listed();
break;
case 'published':
$pages = $this->parent->children();
break;
case 'unlisted':
$pages = $this->parent->children()->unlisted();
break;
default:
$pages = $this->parent->childrenAndDrafts();
}
// filters pages that are protected and not in the templates list
@@ -101,26 +85,13 @@ return [
// 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 and hidden pages
if ($page->isListable() === false) {
// remove all protected pages
if ($page->isReadable() === false) {
return false;
}
$intendedTemplate = $page->intendedTemplate()->name();
// filter by all set templates
if (
$this->templates &&
in_array($intendedTemplate, $this->templates) === false
) {
return false;
}
// exclude by all ignored templates
if (
$this->templatesIgnore &&
in_array($intendedTemplate, $this->templatesIgnore) === true
) {
if ($this->templates && in_array($page->intendedTemplate()->name(), $this->templates) === false) {
return false;
}
@@ -130,11 +101,6 @@ return [
// search
if ($this->search === true && empty($this->searchterm()) === false) {
$pages = $pages->search($this->searchterm());
// disable flip and sortBy while searching
// to show most relevant results
$this->flip = false;
$this->sortBy = null;
}
// sort
@@ -156,16 +122,13 @@ return [
return $pages;
},
'pages' => function () {
return $this->models;
},
'total' => function () {
return $this->models->pagination()->total();
return $this->pages->pagination()->total();
},
'data' => function () {
$data = [];
foreach ($this->models as $page) {
foreach ($this->pages as $page) {
$panel = $page->panel();
$permissions = $page->permissions();
@@ -232,39 +195,11 @@ return [
return false;
}
if ($this->isFull() === true) {
if (in_array($this->status, ['draft', 'all']) === false) {
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]) {
if ($this->isFull() === true) {
return false;
}
@@ -277,41 +212,32 @@ return [
'methods' => [
'blueprints' => function () {
$blueprints = [];
$templates = empty($this->create) === false ? A::wrap($this->create) : $this->templates;
if (empty($templates) === true) {
$templates = $this->kirby()->blueprints();
}
// convert every template to a usable option array
// for the template select box
foreach ($this->blueprintNames() as $blueprint) {
foreach ($templates as $template) {
try {
$props = Blueprint::load('pages/' . $blueprint);
$props = Blueprint::load('pages/' . $template);
$blueprints[] = [
'name' => basename($props['name']),
'title' => $props['title'],
];
} catch (Throwable) {
} catch (Throwable $e) {
$blueprints[] = [
'name' => basename($blueprint),
'title' => ucfirst($blueprint),
'name' => basename($template),
'title' => ucfirst($template),
];
}
}
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;
},
}
],
'toArray' => function () {
return [
@@ -319,7 +245,7 @@ return [
'errors' => $this->errors,
'options' => [
'add' => $this->add,
'columns' => $this->columnsWithTypes(),
'columns' => $this->columns,
'empty' => $this->empty,
'headline' => $this->headline,
'help' => $this->help,

View File

@@ -8,7 +8,7 @@ return [
],
'props' => [
/**
* Array or query string for reports. Each report needs a `label` and `value` and can have additional `info`, `link`, `icon` and `theme` settings.
* 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) {
@@ -34,9 +34,9 @@ return [
],
'computed' => [
'reports' => function () {
$reports = [];
$model = $this->model();
$toString = fn ($value) => $value === null ? null : $model->toString($value);
$reports = [];
$model = $this->model();
$value = fn ($value) => $value === null ? null : $model->toString($value);
foreach ($this->reports as $report) {
if (is_string($report) === true) {
@@ -47,18 +47,12 @@ return [
continue;
}
$info = $report['info'] ?? null;
$label = $report['label'] ?? null;
$link = $report['link'] ?? null;
$value = $report['value'] ?? null;
$reports[] = [
'icon' => $toString($report['icon'] ?? null),
'info' => $toString(I18n::translate($info, $info)),
'label' => $toString(I18n::translate($label, $label)),
'link' => $toString(I18n::translate($link, $link)),
'theme' => $toString($report['theme'] ?? null),
'value' => $toString(I18n::translate($value, $value))
'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)
];
}