Upgrade to 4.0.0

This commit is contained in:
Bastian Allgeier
2023-11-28 09:33:56 +01:00
parent f96b96af76
commit 3b0b6546ca
480 changed files with 21371 additions and 13327 deletions

View File

@@ -60,9 +60,15 @@ class Panel
$areas = $kirby->load()->areas();
// the system is not ready
if ($system->isOk() === false || $system->isInstalled() === false) {
if (
$system->isOk() === false ||
$system->isInstalled() === false
) {
return [
'installation' => static::area('installation', $areas['installation']),
'installation' => static::area(
'installation',
$areas['installation']
),
];
}
@@ -70,7 +76,6 @@ class Panel
if (!$user) {
return [
'logout' => static::area('logout', $areas['logout']),
// login area last because it defines a fallback route
'login' => static::area('login', $areas['login']),
];
@@ -85,24 +90,8 @@ class Panel
unset($areas['languages']);
}
$menu = $kirby->option('panel.menu', [
'site',
'languages',
'users',
'system',
]);
$result = [];
// add the sorted areas
foreach ($menu as $id) {
if ($area = ($areas[$id] ?? null)) {
$result[$id] = static::area($id, $area);
unset($areas[$id]);
}
}
// add the remaining areas
foreach ($areas as $id => $area) {
$result[$id] = static::area($id, $area);
}
@@ -185,7 +174,9 @@ class Panel
$request = App::instance()->request();
if ($request->method() === 'GET') {
return (bool)($request->get('_json') ?? $request->header('X-Fiber'));
return
(bool)($request->get('_json') ??
$request->header('X-Fiber'));
}
return false;
@@ -200,7 +191,7 @@ class Panel
$request = App::instance()->request();
return Response::json($data, $code, $request->get('_pretty'), [
'X-Fiber' => 'true',
'X-Fiber' => 'true',
'Cache-Control' => 'no-store, private'
]);
}
@@ -252,7 +243,9 @@ class Panel
// handle different response types (view, dialog, ...)
return match ($options['type'] ?? null) {
'dialog' => Dialog::response($result, $options),
'drawer' => Drawer::response($result, $options),
'dropdown' => Dropdown::response($result, $options),
'request' => Request::response($result, $options),
'search' => Search::response($result, $options),
default => View::response($result, $options)
};
@@ -291,7 +284,11 @@ class Panel
// call the route action to check the result
try {
// trigger hook
$route = $kirby->apply('panel.route:before', compact('route', 'path', 'method'), 'route');
$route = $kirby->apply(
'panel.route:before',
compact('route', 'path', 'method'),
'route'
);
// check for access before executing area routes
if ($auth !== false) {
@@ -310,7 +307,11 @@ class Panel
'type' => $type
]);
return $kirby->apply('panel.route:after', compact('route', 'path', 'method', 'response'), 'response');
return $kirby->apply(
'panel.route:after',
compact('route', 'path', 'method', 'response'),
'response'
);
});
}
@@ -341,7 +342,9 @@ class Panel
static::routesForViews($areaId, $area),
static::routesForSearches($areaId, $area),
static::routesForDialogs($areaId, $area),
static::routesForDrawers($areaId, $area),
static::routesForDropdowns($areaId, $area),
static::routesForRequests($areaId, $area),
);
}
@@ -362,7 +365,7 @@ class Panel
// catch all route
$routes[] = [
'pattern' => '(:all)',
'action' => fn () => 'The view could not be found'
'action' => fn (string $pattern) => 'Could not find Panel view for route: ' . $pattern
];
return $routes;
@@ -376,26 +379,33 @@ class Panel
$dialogs = $area['dialogs'] ?? [];
$routes = [];
foreach ($dialogs as $key => $dialog) {
// create the full pattern with dialogs prefix
$pattern = 'dialogs/' . trim(($dialog['pattern'] ?? $key), '/');
foreach ($dialogs as $dialogId => $dialog) {
$routes = array_merge($routes, Dialog::routes(
id: $dialogId,
areaId: $areaId,
prefix: 'dialogs',
options: $dialog
));
}
// load event
$routes[] = [
'pattern' => $pattern,
'type' => 'dialog',
'area' => $areaId,
'action' => $dialog['load'] ?? fn () => 'The load handler for your dialog is missing'
];
return $routes;
}
// submit event
$routes[] = [
'pattern' => $pattern,
'type' => 'dialog',
'area' => $areaId,
'method' => 'POST',
'action' => $dialog['submit'] ?? fn () => 'Your dialog does not define a submit handler'
];
/**
* Extract all routes from an area
*/
public static function routesForDrawers(string $areaId, array $area): array
{
$drawers = $area['drawers'] ?? [];
$routes = [];
foreach ($drawers as $drawerId => $drawer) {
$routes = array_merge($routes, Drawer::routes(
id: $drawerId,
areaId: $areaId,
prefix: 'drawers',
options: $drawer
));
}
return $routes;
@@ -409,27 +419,28 @@ class Panel
$dropdowns = $area['dropdowns'] ?? [];
$routes = [];
foreach ($dropdowns as $name => $dropdown) {
// Handle shortcuts for dropdowns. The name is the pattern
// and options are defined in a Closure
if ($dropdown instanceof Closure) {
$dropdown = [
'pattern' => $name,
'action' => $dropdown
];
}
foreach ($dropdowns as $dropdownId => $dropdown) {
$routes = array_merge($routes, Dropdown::routes(
id: $dropdownId,
areaId: $areaId,
prefix: 'dropdowns',
options: $dropdown
));
}
// create the full pattern with dropdowns prefix
$pattern = 'dropdowns/' . trim(($dropdown['pattern'] ?? $name), '/');
return $routes;
}
// load event
$routes[] = [
'pattern' => $pattern,
'type' => 'dropdown',
'area' => $areaId,
'method' => 'GET|POST',
'action' => $dropdown['options'] ?? $dropdown['action']
];
/**
* Extract all routes from an area
*/
public static function routesForRequests(string $areaId, array $area): array
{
$routes = $area['requests'] ?? [];
foreach ($routes as $key => $route) {
$routes[$key]['area'] = $areaId;
$routes[$key]['type'] = 'request';
}
return $routes;
@@ -453,9 +464,13 @@ class Panel
'type' => 'search',
'area' => $areaId,
'action' => function () use ($params) {
$request = App::instance()->request();
$kirby = App::instance();
$request = $kirby->request();
$query = $request->get('query');
$limit = (int)$request->get('limit', $kirby->option('panel.search.limit', 10));
$page = (int)$request->get('page', 1);
return $params['query']($request->get('query'));
return $params['query']($query, $limit, $page);
}
];
}
@@ -474,7 +489,18 @@ class Panel
foreach ($views as $view) {
$view['area'] = $areaId;
$view['type'] = 'view';
$routes[] = $view;
$when = $view['when'] ?? null;
unset($view['when']);
// enable the route by default, but if there is a
// when condition closure, it must return `true`
if (
$when instanceof Closure === false ||
$when($view, $area) === true
) {
$routes[] = $view;
}
}
return $routes;
@@ -537,7 +563,7 @@ class Panel
* Creates an absolute Panel URL
* independent of the Panel slug config
*/
public static function url(string|null $url = null): string
public static function url(string|null $url = null, array $options = []): string
{
// only touch relative paths
if (Url::isAbsolute($url) === false) {
@@ -559,7 +585,7 @@ class Panel
}
// create an absolute URL
$url = CmsUrl::to($path);
$url = CmsUrl::to($path, $options);
}
return $url;