xiaowang/kirby/config/api/models/Page.php

129 lines
4.1 KiB
PHP
Raw Normal View History

2021-10-29 18:05:46 +02:00
<?php
use Kirby\Cms\Page;
2021-11-18 17:44:47 +01:00
use Kirby\Form\Form;
2021-10-29 18:05:46 +02:00
/**
* Page
*/
return [
'fields' => [
2022-03-22 15:39:39 +01:00
'blueprint' => fn (Page $page) => $page->blueprint(),
'blueprints' => fn (Page $page) => $page->blueprints(),
'children' => fn (Page $page) => $page->children(),
'content' => fn (Page $page) => Form::for($page)->values(),
'drafts' => fn (Page $page) => $page->drafts(),
'errors' => fn (Page $page) => $page->errors(),
'files' => fn (Page $page) => $page->files()->sorted(),
'hasChildren' => fn (Page $page) => $page->hasChildren(),
'hasDrafts' => fn (Page $page) => $page->hasDrafts(),
'hasFiles' => fn (Page $page) => $page->hasFiles(),
'id' => fn (Page $page) => $page->id(),
'isSortable' => fn (Page $page) => $page->isSortable(),
2021-11-18 17:44:47 +01:00
/**
* @deprecated 3.6.0
* @todo Throw deprecated warning in 3.7.0
* @todo Remove in 3.8.0
* @codeCoverageIgnore
*/
2021-10-29 18:05:46 +02:00
'next' => function (Page $page) {
return $page
->nextAll()
->filter('intendedTemplate', $page->intendedTemplate())
->filter('status', $page->status())
->filter('isReadable', true)
->first();
},
2022-03-22 15:39:39 +01:00
'num' => fn (Page $page) => $page->num(),
'options' => fn (Page $page) => $page->panel()->options(['preview']),
2021-11-18 17:44:47 +01:00
/**
* @todo Remove in 3.7.0
* @codeCoverageIgnore
*/
2021-10-29 18:05:46 +02:00
'panelIcon' => function (Page $page) {
2021-11-18 17:44:47 +01:00
deprecated('The API field page.panelIcon has been deprecated and will be removed in 3.7.0. Use page.panelImage instead');
return $page->panel()->image();
2021-10-29 18:05:46 +02:00
},
2022-03-22 15:39:39 +01:00
'panelImage' => fn (Page $page) => $page->panel()->image(),
'parent' => fn (Page $page) => $page->parent(),
'parents' => fn (Page $page) => $page->parents()->flip(),
2021-11-18 17:44:47 +01:00
/**
* @deprecated 3.6.0
* @todo Throw deprecated warning in 3.7.0
* @todo Remove in 3.8.0
* @codeCoverageIgnore
*/
2021-10-29 18:05:46 +02:00
'prev' => function (Page $page) {
return $page
->prevAll()
->filter('intendedTemplate', $page->intendedTemplate())
->filter('status', $page->status())
->filter('isReadable', true)
->last();
},
2022-03-22 15:39:39 +01:00
'previewUrl' => fn (Page $page) => $page->previewUrl(),
'siblings' => function (Page $page) {
2021-10-29 18:05:46 +02:00
if ($page->isDraft() === true) {
return $page->parentModel()->children()->not($page);
} else {
return $page->siblings();
}
},
2022-03-22 15:39:39 +01:00
'slug' => fn (Page $page) => $page->slug(),
'status' => fn (Page $page) => $page->status(),
'template' => fn (Page $page) => $page->intendedTemplate()->name(),
'title' => fn (Page $page) => $page->title()->value(),
'url' => fn (Page $page) => $page->url(),
2021-10-29 18:05:46 +02:00
],
'type' => 'Kirby\Cms\Page',
'views' => [
'compact' => [
'id',
'title',
'url',
'num'
],
'default' => [
'content',
'id',
'status',
'num',
'options',
'parent' => 'compact',
'slug',
'template',
'title',
'url'
],
'panel' => [
'id',
'blueprint',
'content',
'status',
'options',
'next' => ['id', 'slug', 'title'],
'parents' => ['id', 'slug', 'title'],
'prev' => ['id', 'slug', 'title'],
'previewUrl',
'slug',
'title',
'url'
],
'selector' => [
'id',
'title',
'parent' => [
'id',
'title'
],
'children' => [
'hasChildren',
'id',
'panelIcon',
'panelImage',
'title',
],
]
],
];