downgrade to kirby v3
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user