Upgrade to 3.6.2
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
namespace Kirby\Panel;
|
||||
|
||||
use Kirby\Exception\Exception;
|
||||
use Kirby\Exception\InvalidArgumentException;
|
||||
use Kirby\Filesystem\Dir;
|
||||
use Kirby\Filesystem\F;
|
||||
use Kirby\Http\Response;
|
||||
@@ -65,22 +66,9 @@ class Document
|
||||
'css' => [
|
||||
'index' => $url . '/css/style.css',
|
||||
'plugins' => $plugins->url('css'),
|
||||
'custom' => static::customCss(),
|
||||
'custom' => static::customAsset('panel.css'),
|
||||
],
|
||||
'icons' => $kirby->option('panel.favicon', [
|
||||
'apple-touch-icon' => [
|
||||
'type' => 'image/png',
|
||||
'url' => $url . '/apple-touch-icon.png',
|
||||
],
|
||||
'shortcut icon' => [
|
||||
'type' => 'image/svg+xml',
|
||||
'url' => $url . '/favicon.svg',
|
||||
],
|
||||
'alternate icon' => [
|
||||
'type' => 'image/png',
|
||||
'url' => $url . '/favicon.png',
|
||||
]
|
||||
]),
|
||||
'icons' => static::favicon($url),
|
||||
'js' => [
|
||||
'vendor' => [
|
||||
'nonce' => $nonce,
|
||||
@@ -99,7 +87,7 @@ class Document
|
||||
],
|
||||
'custom' => [
|
||||
'nonce' => $nonce,
|
||||
'src' => static::customJs(),
|
||||
'src' => static::customAsset('panel.js'),
|
||||
'type' => 'module'
|
||||
],
|
||||
'index' => [
|
||||
@@ -139,15 +127,17 @@ class Document
|
||||
}
|
||||
|
||||
/**
|
||||
* Check for a custom css file from the
|
||||
* config (panel.css)
|
||||
* Check for a custom asset file from the
|
||||
* config (e.g. panel.css or panel.js)
|
||||
* @since 3.6.2
|
||||
*
|
||||
* @param string $option asset option name
|
||||
* @return string|null
|
||||
*/
|
||||
public static function customCss(): ?string
|
||||
public static function customAsset(string $option): ?string
|
||||
{
|
||||
if ($css = kirby()->option('panel.css')) {
|
||||
$asset = asset($css);
|
||||
if ($path = kirby()->option($option)) {
|
||||
$asset = asset($path);
|
||||
|
||||
if ($asset->exists() === true) {
|
||||
return $asset->url() . '?' . $asset->modified();
|
||||
@@ -158,22 +148,64 @@ class Document
|
||||
}
|
||||
|
||||
/**
|
||||
* Check for a custom js file from the
|
||||
* config (panel.js)
|
||||
*
|
||||
* @return string|null
|
||||
* @deprecated 3.7.0 Use `Document::customAsset('panel.css)` instead
|
||||
* @todo add deprecation warning in 3.7.0, remove in 3.8.0
|
||||
*/
|
||||
public static function customCss(): ?string
|
||||
{
|
||||
return static::customAsset('panel.css');
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated 3.7.0 Use `Document::customAsset('panel.js)` instead
|
||||
* @todo add deprecation warning in 3.7.0, remove in 3.8.0
|
||||
*/
|
||||
public static function customJs(): ?string
|
||||
{
|
||||
if ($js = kirby()->option('panel.js')) {
|
||||
$asset = asset($js);
|
||||
return static::customAsset('panel.js');
|
||||
}
|
||||
|
||||
if ($asset->exists() === true) {
|
||||
return $asset->url() . '?' . $asset->modified();
|
||||
}
|
||||
/**
|
||||
* Returns array of favion icons
|
||||
* based on config option
|
||||
* @since 3.6.2
|
||||
*
|
||||
* @param string $url URL prefix for default icons
|
||||
* @return array
|
||||
*/
|
||||
public static function favicon(string $url = ''): array
|
||||
{
|
||||
$kirby = kirby();
|
||||
$icons = $kirby->option('panel.favicon', [
|
||||
'apple-touch-icon' => [
|
||||
'type' => 'image/png',
|
||||
'url' => $url . '/apple-touch-icon.png',
|
||||
],
|
||||
'shortcut icon' => [
|
||||
'type' => 'image/svg+xml',
|
||||
'url' => $url . '/favicon.svg',
|
||||
],
|
||||
'alternate icon' => [
|
||||
'type' => 'image/png',
|
||||
'url' => $url . '/favicon.png',
|
||||
]
|
||||
]);
|
||||
|
||||
if (is_array($icons) === true) {
|
||||
return $icons;
|
||||
}
|
||||
|
||||
return null;
|
||||
// make sure to convert favicon string to array
|
||||
if (is_string($icons) === true) {
|
||||
return [
|
||||
'shortcut icon' => [
|
||||
'type' => F::mime($icons),
|
||||
'url' => $icons,
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
throw new InvalidArgumentException('Invalid panel.favicon option');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -38,12 +38,10 @@ class File extends Model
|
||||
}
|
||||
break;
|
||||
case 'page':
|
||||
$breadcrumb = $this->model->parents()->flip()->values(function ($parent) {
|
||||
return [
|
||||
'label' => $parent->title()->toString(),
|
||||
'link' => $parent->panel()->url(true),
|
||||
];
|
||||
});
|
||||
$breadcrumb = $this->model->parents()->flip()->values(fn ($parent) => [
|
||||
'label' => $parent->title()->toString(),
|
||||
'link' => $parent->panel()->url(true),
|
||||
]);
|
||||
}
|
||||
|
||||
// add the file
|
||||
@@ -459,13 +457,11 @@ class File extends Model
|
||||
$file = $this->model;
|
||||
|
||||
return [
|
||||
'breadcrumb' => function () use ($file): array {
|
||||
return $file->panel()->breadcrumb();
|
||||
},
|
||||
'component' => 'k-file-view',
|
||||
'props' => $this->props(),
|
||||
'search' => 'files',
|
||||
'title' => $file->filename(),
|
||||
'breadcrumb' => fn (): array => $file->panel()->breadcrumb(),
|
||||
'component' => 'k-file-view',
|
||||
'props' => $this->props(),
|
||||
'search' => 'files',
|
||||
'title' => $file->filename(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@@ -22,12 +22,10 @@ class Page extends Model
|
||||
public function breadcrumb(): array
|
||||
{
|
||||
$parents = $this->model->parents()->flip()->merge($this->model);
|
||||
return $parents->values(function ($parent) {
|
||||
return [
|
||||
'label' => $parent->title()->toString(),
|
||||
'link' => $parent->panel()->url(true),
|
||||
];
|
||||
});
|
||||
return $parents->values(fn ($parent) => [
|
||||
'label' => $parent->title()->toString(),
|
||||
'link' => $parent->panel()->url(true),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -353,11 +353,9 @@ class Panel
|
||||
[
|
||||
'pattern' => 'browser',
|
||||
'auth' => false,
|
||||
'action' => function () use ($kirby) {
|
||||
return new Response(
|
||||
Tpl::load($kirby->root('kirby') . '/views/browser.php')
|
||||
);
|
||||
},
|
||||
'action' => fn () => new Response(
|
||||
Tpl::load($kirby->root('kirby') . '/views/browser.php')
|
||||
),
|
||||
]
|
||||
];
|
||||
|
||||
@@ -382,17 +380,14 @@ class Panel
|
||||
'installation',
|
||||
'login',
|
||||
],
|
||||
'action' => function () {
|
||||
Panel::go(Home::url());
|
||||
}
|
||||
'action' => fn () => Panel::go(Home::url()),
|
||||
'auth' => false
|
||||
];
|
||||
|
||||
// catch all route
|
||||
$routes[] = [
|
||||
'pattern' => '(:all)',
|
||||
'action' => function () {
|
||||
return 'The view could not be found';
|
||||
}
|
||||
'action' => fn () => 'The view could not be found'
|
||||
];
|
||||
|
||||
return $routes;
|
||||
@@ -420,9 +415,7 @@ class Panel
|
||||
'pattern' => $pattern,
|
||||
'type' => 'dialog',
|
||||
'area' => $areaId,
|
||||
'action' => $dialog['load'] ?? function () {
|
||||
return 'The load handler for your dialog is missing';
|
||||
},
|
||||
'action' => $dialog['load'] ?? fn () => 'The load handler for your dialog is missing'
|
||||
];
|
||||
|
||||
// submit event
|
||||
@@ -431,9 +424,7 @@ class Panel
|
||||
'type' => 'dialog',
|
||||
'area' => $areaId,
|
||||
'method' => 'POST',
|
||||
'action' => $dialog['submit'] ?? function () {
|
||||
return 'Your dialog does not define a submit handler';
|
||||
}
|
||||
'action' => $dialog['submit'] ?? fn () => 'Your dialog does not define a submit handler'
|
||||
];
|
||||
}
|
||||
|
||||
|
@@ -178,15 +178,13 @@ class View
|
||||
},
|
||||
'$languages' => function () use ($kirby, $multilang): array {
|
||||
if ($multilang === true) {
|
||||
return $kirby->languages()->values(function ($language) {
|
||||
return [
|
||||
'code' => $language->code(),
|
||||
'default' => $language->isDefault(),
|
||||
'direction' => $language->direction(),
|
||||
'name' => $language->name(),
|
||||
'rules' => $language->rules(),
|
||||
];
|
||||
});
|
||||
return $kirby->languages()->values(fn ($language) => [
|
||||
'code' => $language->code(),
|
||||
'default' => $language->isDefault(),
|
||||
'direction' => $language->direction(),
|
||||
'name' => $language->name(),
|
||||
'rules' => $language->rules(),
|
||||
]);
|
||||
}
|
||||
|
||||
return [];
|
||||
@@ -315,12 +313,10 @@ class View
|
||||
'name' => $translation->name(),
|
||||
];
|
||||
},
|
||||
'$urls' => function () use ($kirby) {
|
||||
return [
|
||||
'api' => $kirby->url('api'),
|
||||
'site' => $kirby->url('index')
|
||||
];
|
||||
}
|
||||
'$urls' => fn () => [
|
||||
'api' => $kirby->url('api'),
|
||||
'site' => $kirby->url('index')
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
@@ -401,10 +397,6 @@ class View
|
||||
*/
|
||||
public static function response($data, array $options = [])
|
||||
{
|
||||
$kirby = kirby();
|
||||
$area = $options['area'] ?? [];
|
||||
$areas = $options['areas'] ?? [];
|
||||
|
||||
// handle redirects
|
||||
if (is_a($data, 'Kirby\Panel\Redirect') === true) {
|
||||
return Response::redirect($data->location(), $data->code());
|
||||
|
Reference in New Issue
Block a user