Upgrade to 3.6.0

This commit is contained in:
Bastian Allgeier
2021-11-16 14:53:37 +01:00
parent 7388fa4d24
commit 92b7a330fa
318 changed files with 20017 additions and 6878 deletions

View File

@@ -5,10 +5,11 @@ namespace Kirby\Cms;
use Kirby\Exception\Exception;
use Kirby\Exception\InvalidArgumentException;
use Kirby\Exception\NotFoundException;
use Kirby\Filesystem\Dir;
use Kirby\Filesystem\F;
use Kirby\Http\Uri;
use Kirby\Panel\Page as Panel;
use Kirby\Toolkit\A;
use Kirby\Toolkit\Escape;
use Kirby\Toolkit\F;
/**
* The `$page` object is the heart and
@@ -171,7 +172,7 @@ class Page extends ModelWithContent
}
// return page content otherwise
return $this->content()->get($method, $arguments);
return $this->content()->get($method);
}
/**
@@ -214,9 +215,9 @@ class Page extends ModelWithContent
public function apiUrl(bool $relative = false): string
{
if ($relative === true) {
return 'pages/' . $this->panelId();
return 'pages/' . $this->panel()->id();
} else {
return $this->kirby()->url('api') . '/pages/' . $this->panelId();
return $this->kirby()->url('api') . '/pages/' . $this->panel()->id();
}
}
@@ -335,7 +336,7 @@ class Page extends ModelWithContent
* @return array
* @throws \Kirby\Exception\InvalidArgumentException If the controller returns invalid objects for `kirby`, `site`, `pages` or `page`
*/
public function controller($data = [], $contentType = 'html'): array
public function controller(array $data = [], string $contentType = 'html'): array
{
// create the template data
$data = array_merge($data, [
@@ -426,31 +427,6 @@ class Page extends ModelWithContent
}
}
/**
* Provides a kirbytag or markdown
* tag for the page, which will be
* used in the panel, when the page
* gets dragged onto a textarea
*
* @internal
* @param string|null $type (null|auto|kirbytext|markdown)
* @return string
*/
public function dragText(string $type = null): string
{
$type = $this->dragTextType($type);
if ($dragTextFromCallback = $this->dragTextFromCallback($type)) {
return $dragTextFromCallback;
}
if ($type === 'markdown') {
return '[' . $this->title() . '](' . $this->url() . ')';
} else {
return '(link: ' . $this->id() . ' text: ' . $this->title() . ')';
}
}
/**
* Checks if the page exists on disk
*
@@ -929,109 +905,13 @@ class Page extends ModelWithContent
}
/**
* Returns the panel icon definition
* according to the blueprint settings
* Returns the panel info object
*
* @internal
* @param array|null $params
* @return array
* @return \Kirby\Panel\Page
*/
public function panelIcon(array $params = null): array
public function panel()
{
if ($icon = $this->blueprint()->icon()) {
$params['type'] = $icon;
}
return parent::panelIcon($params);
}
/**
* Returns the escaped Id, which is
* used in the panel to make routing work properly
*
* @internal
* @return string
*/
public function panelId(): string
{
return str_replace('/', '+', $this->id());
}
/**
* Returns the image file object based on provided query
*
* @internal
* @param string|null $query
* @return \Kirby\Cms\File|\Kirby\Cms\Asset|null
*/
protected function panelImageSource(string $query = null)
{
if ($query === null) {
$query = 'page.image';
}
return parent::panelImageSource($query);
}
/**
* Returns the full path without leading slash
*
* @internal
* @return string
*/
public function panelPath(): string
{
return 'pages/' . $this->panelId();
}
/**
* Prepares the response data for page pickers
* and page fields
*
* @param array|null $params
* @return array
*/
public function panelPickerData(array $params = []): array
{
$image = $this->panelImage($params['image'] ?? []);
$icon = $this->panelIcon($image);
// escape the default text
// TODO: no longer needed in 3.6
$textQuery = $params['text'] ?? '{{ page.title }}';
$text = $this->toString($textQuery);
if ($textQuery === '{{ page.title }}') {
$text = Escape::html($text);
}
return [
'dragText' => $this->dragText(),
'hasChildren' => $this->hasChildren(),
'icon' => $icon,
'id' => $this->id(),
'image' => $image,
'info' => $this->toString($params['info'] ?? false),
'link' => $this->panelUrl(true),
'text' => $text,
'url' => $this->url(),
];
}
/**
* Returns the url to the editing view
* in the panel
*
* @internal
* @param bool $relative
* @return string
*/
public function panelUrl(bool $relative = false): string
{
if ($relative === true) {
return '/' . $this->panelPath();
} else {
return $this->kirby()->url('panel') . '/' . $this->panelPath();
}
return new Panel($this);
}
/**
@@ -1383,7 +1263,9 @@ class Page extends ModelWithContent
$languageCode = $this->kirby()->languageCode();
}
if ($translation = $this->translations()->find($languageCode)) {
$defaultLanguageCode = $this->kirby()->defaultLanguage()->code();
if ($languageCode !== $defaultLanguageCode && $translation = $this->translations()->find($languageCode)) {
return $translation->slug() ?? $this->slug;
}
}
@@ -1576,4 +1458,97 @@ class Page extends ModelWithContent
return $this->url = $this->site()->urlForLanguage($language) . '/' . $this->slug($language);
}
/**
* Deprecated!
*/
/**
* Provides a kirbytag or markdown
* tag for the page, which will be
* used in the panel, when the page
* gets dragged onto a textarea
*
* @deprecated 3.6.0 Use `->panel()->dragText()` instead
* @todo Add `deprecated()` helper warning in 3.7.0
* @todo Remove in 3.8.0
*
* @internal
* @param string|null $type (null|auto|kirbytext|markdown)
* @return string
* @codeCoverageIgnore
*/
public function dragText(string $type = null): string
{
return $this->panel()->dragText($type);
}
/**
* Returns the escaped Id, which is
* used in the panel to make routing work properly
*
* @deprecated 3.6.0 Use `->panel()->id()` instead
* @todo Add `deprecated()` helper warning in 3.7.0
* @todo Remove in 3.8.0
*
* @internal
* @return string
* @codeCoverageIgnore
*/
public function panelId(): string
{
return $this->panel()->id();
}
/**
* Returns the full path without leading slash
*
* @deprecated 3.6.0 Use `->panel()->path()` instead
* @todo Add `deprecated()` helper warning in 3.7.0
* @todo Remove in 3.8.0
*
* @internal
* @return string
* @codeCoverageIgnore
*/
public function panelPath(): string
{
return $this->panel()->path();
}
/**
* Prepares the response data for page pickers
* and page fields
*
* @deprecated 3.6.0 Use `->panel()->pickerData()` instead
* @todo Add `deprecated()` helper warning in 3.7.0
* @todo Remove in 3.8.0
*
* @param array|null $params
* @return array
* @codeCoverageIgnore
*/
public function panelPickerData(array $params = []): array
{
return $this->panel()->pickerData($params);
}
/**
* Returns the url to the editing view
* in the panel
*
* @deprecated 3.6.0 Use `->panel()->url()` instead
* @todo Add `deprecated()` helper warning in 3.7.0
* @todo Remove in 3.8.0
*
* @internal
* @param bool $relative
* @return string
* @codeCoverageIgnore
*/
public function panelUrl(bool $relative = false): string
{
return $this->panel()->url($relative);
}
}