update kirby to v5 and add refresh cache panel view button
This commit is contained in:
commit
9a86d41254
466 changed files with 19960 additions and 10497 deletions
|
|
@ -2,8 +2,11 @@
|
|||
|
||||
namespace Kirby\Cms;
|
||||
|
||||
use Kirby\Exception\Exception;
|
||||
use Kirby\Exception\InvalidArgumentException;
|
||||
use Kirby\Exception\NotFoundException;
|
||||
use Kirby\Uuid\HasUuids;
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
* The `$pages` object refers to a
|
||||
|
|
@ -20,6 +23,8 @@ use Kirby\Uuid\HasUuids;
|
|||
* @link https://getkirby.com
|
||||
* @copyright Bastian Allgeier
|
||||
* @license https://getkirby.com/license
|
||||
*
|
||||
* @extends \Kirby\Cms\Collection<\Kirby\Cms\Page>
|
||||
*/
|
||||
class Pages extends Collection
|
||||
{
|
||||
|
|
@ -27,23 +32,24 @@ class Pages extends Collection
|
|||
|
||||
/**
|
||||
* Cache for the index only listed and unlisted pages
|
||||
*
|
||||
* @var \Kirby\Cms\Pages|null
|
||||
*/
|
||||
protected $index = null;
|
||||
protected Pages|null $index = null;
|
||||
|
||||
/**
|
||||
* Cache for the index all statuses also including drafts
|
||||
*
|
||||
* @var \Kirby\Cms\Pages|null
|
||||
*/
|
||||
protected $indexWithDrafts = null;
|
||||
protected Pages|null $indexWithDrafts = null;
|
||||
|
||||
/**
|
||||
* All registered pages methods
|
||||
*/
|
||||
public static array $methods = [];
|
||||
|
||||
/**
|
||||
* @var \Kirby\Cms\Page|\Kirby\Cms\Site|null
|
||||
*/
|
||||
protected object|null $parent = null;
|
||||
|
||||
/**
|
||||
* Adds a single page or
|
||||
* an entire second collection to the
|
||||
|
|
@ -59,23 +65,25 @@ class Pages extends Collection
|
|||
|
||||
// add a pages collection
|
||||
if ($object instanceof self) {
|
||||
$this->data = array_merge($this->data, $object->data);
|
||||
$this->data = [...$this->data, ...$object->data];
|
||||
|
||||
// add a page by id
|
||||
// add a page by id
|
||||
} elseif (
|
||||
is_string($object) === true &&
|
||||
$page = $site->find($object)
|
||||
) {
|
||||
$this->__set($page->id(), $page);
|
||||
|
||||
// add a page object
|
||||
// add a page object
|
||||
} elseif ($object instanceof Page) {
|
||||
$this->__set($object->id(), $object);
|
||||
|
||||
// give a useful error message on invalid input;
|
||||
// silently ignore "empty" values for compatibility with existing setups
|
||||
// give a useful error message on invalid input;
|
||||
// silently ignore "empty" values for compatibility with existing setups
|
||||
} elseif (in_array($object, [null, false, true], true) !== true) {
|
||||
throw new InvalidArgumentException('You must pass a Pages or Page object or an ID of an existing page to the Pages collection');
|
||||
throw new InvalidArgumentException(
|
||||
message: 'You must pass a Pages or Page object or an ID of an existing page to the Pages collection'
|
||||
);
|
||||
}
|
||||
|
||||
return $this;
|
||||
|
|
@ -92,9 +100,9 @@ class Pages extends Collection
|
|||
/**
|
||||
* Returns all children for each page in the array
|
||||
*/
|
||||
public function children(): Pages
|
||||
public function children(): static
|
||||
{
|
||||
$children = new Pages([]);
|
||||
$children = new static([]);
|
||||
|
||||
foreach ($this->data as $page) {
|
||||
foreach ($page->children() as $childKey => $child) {
|
||||
|
|
@ -113,6 +121,41 @@ class Pages extends Collection
|
|||
return $this->files()->filter('type', 'code');
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes the pages with the given IDs
|
||||
* if they exist in the collection
|
||||
*
|
||||
* @throws \Kirby\Exception\Exception If not all pages could be deleted
|
||||
*/
|
||||
public function delete(array $ids): void
|
||||
{
|
||||
$exceptions = [];
|
||||
|
||||
// delete all pages and collect errors
|
||||
foreach ($ids as $id) {
|
||||
try {
|
||||
$model = $this->get($id);
|
||||
|
||||
if ($model instanceof Page === false) {
|
||||
throw new NotFoundException(
|
||||
key: 'page.undefined',
|
||||
);
|
||||
}
|
||||
|
||||
$model->delete();
|
||||
} catch (Throwable $e) {
|
||||
$exceptions[$id] = $e;
|
||||
}
|
||||
}
|
||||
|
||||
if ($exceptions !== []) {
|
||||
throw new Exception(
|
||||
key: 'page.delete.multiple',
|
||||
details: $exceptions
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all documents of all children
|
||||
*/
|
||||
|
|
@ -124,9 +167,9 @@ class Pages extends Collection
|
|||
/**
|
||||
* Fetch all drafts for all pages in the collection
|
||||
*/
|
||||
public function drafts(): Pages
|
||||
public function drafts(): static
|
||||
{
|
||||
$drafts = new Pages([]);
|
||||
$drafts = new static([]);
|
||||
|
||||
foreach ($this->data as $page) {
|
||||
foreach ($page->drafts() as $draftKey => $draft) {
|
||||
|
|
@ -203,7 +246,7 @@ class Pages extends Collection
|
|||
$key = trim($key, '/');
|
||||
|
||||
// strip extensions from the id
|
||||
if (strpos($key, '.') !== false) {
|
||||
if (str_contains($key, '.') === true) {
|
||||
$info = pathinfo($key);
|
||||
|
||||
if ($info['dirname'] !== '.') {
|
||||
|
|
@ -243,14 +286,12 @@ class Pages extends Collection
|
|||
|
||||
/**
|
||||
* Finds a child or child of a child recursively
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
protected function findByKeyRecursive(
|
||||
string $id,
|
||||
string|null $startAt = null,
|
||||
bool $multiLang = false
|
||||
) {
|
||||
): Page|null {
|
||||
$path = explode('/', $id);
|
||||
$item = null;
|
||||
$query = $startAt;
|
||||
|
|
@ -294,12 +335,8 @@ class Pages extends Collection
|
|||
/**
|
||||
* Custom getter that is able to find
|
||||
* extension pages
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $default
|
||||
* @return \Kirby\Cms\Page|null
|
||||
*/
|
||||
public function get($key, $default = null)
|
||||
public function get(string $key, mixed $default = null): Page|null
|
||||
{
|
||||
if ($key === null) {
|
||||
return null;
|
||||
|
|
@ -323,19 +360,17 @@ class Pages extends Collection
|
|||
/**
|
||||
* Create a recursive flat index of all
|
||||
* pages and subpages, etc.
|
||||
*
|
||||
* @return \Kirby\Cms\Pages
|
||||
*/
|
||||
public function index(bool $drafts = false)
|
||||
public function index(bool $drafts = false): static
|
||||
{
|
||||
// get object property by cache mode
|
||||
$index = $drafts === true ? $this->indexWithDrafts : $this->index;
|
||||
|
||||
if ($index instanceof self) {
|
||||
if ($index instanceof Pages) {
|
||||
return $index;
|
||||
}
|
||||
|
||||
$index = new Pages([]);
|
||||
$index = new static([]);
|
||||
|
||||
foreach ($this->data as $pageKey => $page) {
|
||||
$index->data[$pageKey] = $page;
|
||||
|
|
@ -374,10 +409,9 @@ class Pages extends Collection
|
|||
/**
|
||||
* Include all given items in the collection
|
||||
*
|
||||
* @param mixed ...$args
|
||||
* @return $this|static
|
||||
*/
|
||||
public function merge(...$args)
|
||||
public function merge(string|Pages|Page|array ...$args): static
|
||||
{
|
||||
// merge multiple arguments at once
|
||||
if (count($args) > 1) {
|
||||
|
|
@ -398,9 +432,9 @@ class Pages extends Collection
|
|||
}
|
||||
|
||||
// merge an entire collection
|
||||
if ($args[0] instanceof self) {
|
||||
$collection = clone $this;
|
||||
$collection->data = array_merge($collection->data, $args[0]->data);
|
||||
if ($args[0] instanceof Pages) {
|
||||
$collection = clone $this;
|
||||
$collection->data = [...$collection->data, ...$args[0]->data];
|
||||
return $collection;
|
||||
}
|
||||
|
||||
|
|
@ -430,10 +464,9 @@ class Pages extends Collection
|
|||
* Filter all pages by excluding the given template
|
||||
* @since 3.3.0
|
||||
*
|
||||
* @param string|array $templates
|
||||
* @return \Kirby\Cms\Pages
|
||||
* @return $this|static
|
||||
*/
|
||||
public function notTemplate($templates)
|
||||
public function notTemplate(string|array|null $templates): static
|
||||
{
|
||||
if (empty($templates) === true) {
|
||||
return $this;
|
||||
|
|
@ -444,8 +477,7 @@ class Pages extends Collection
|
|||
}
|
||||
|
||||
return $this->filter(
|
||||
fn ($page) =>
|
||||
!in_array($page->intendedTemplate()->name(), $templates)
|
||||
fn ($page) => in_array($page->intendedTemplate()->name(), $templates, true) === false
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -466,10 +498,9 @@ class Pages extends Collection
|
|||
/**
|
||||
* Filter all pages by the given template
|
||||
*
|
||||
* @param string|array $templates
|
||||
* @return \Kirby\Cms\Pages
|
||||
* @return $this|static
|
||||
*/
|
||||
public function template($templates)
|
||||
public function template(string|array|null $templates): static
|
||||
{
|
||||
if (empty($templates) === true) {
|
||||
return $this;
|
||||
|
|
@ -480,8 +511,7 @@ class Pages extends Collection
|
|||
}
|
||||
|
||||
return $this->filter(
|
||||
fn ($page) =>
|
||||
in_array($page->intendedTemplate()->name(), $templates)
|
||||
fn ($page) => in_array($page->intendedTemplate()->name(), $templates, true)
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue