xiaowang/kirby/config/presets/pages.php

59 lines
1.3 KiB
PHP
Raw Normal View History

2021-10-29 18:05:46 +02:00
<?php
2022-08-31 16:08:03 +02:00
use Kirby\Toolkit\I18n;
2021-10-29 18:05:46 +02:00
2022-08-31 16:08:03 +02:00
return function (array $props) {
// load the general templates setting for all sections
$templates = $props['templates'] ?? null;
2021-10-29 18:05:46 +02:00
2022-12-19 16:26:24 +01:00
$section = function ($label, $status, $props) use ($templates) {
2022-08-31 16:08:03 +02:00
$defaults = [
2022-12-19 16:26:24 +01:00
'label' => $label,
'type' => 'pages',
'layout' => 'list',
'status' => $status
2022-08-31 16:08:03 +02:00
];
2021-10-29 18:05:46 +02:00
2022-08-31 16:08:03 +02:00
if ($props === true) {
$props = [];
}
2021-10-29 18:05:46 +02:00
2022-08-31 16:08:03 +02:00
if (is_string($props) === true) {
$props = [
2022-12-19 16:26:24 +01:00
'label' => $props
2022-08-31 16:08:03 +02:00
];
}
2021-10-29 18:05:46 +02:00
2022-08-31 16:08:03 +02:00
// inject the global templates definition
if (empty($templates) === false) {
$props['templates'] = $props['templates'] ?? $templates;
}
2021-10-29 18:05:46 +02:00
2022-08-31 16:08:03 +02:00
return array_replace_recursive($defaults, $props);
};
2021-10-29 18:05:46 +02:00
2022-08-31 16:08:03 +02:00
$sections = [];
2021-10-29 18:05:46 +02:00
2022-08-31 16:08:03 +02:00
$drafts = $props['drafts'] ?? [];
$unlisted = $props['unlisted'] ?? false;
$listed = $props['listed'] ?? [];
2021-10-29 18:05:46 +02:00
2022-08-31 16:08:03 +02:00
if ($drafts !== false) {
$sections['drafts'] = $section(I18n::translate('pages.status.draft'), 'drafts', $drafts);
}
2021-10-29 18:05:46 +02:00
2022-08-31 16:08:03 +02:00
if ($unlisted !== false) {
$sections['unlisted'] = $section(I18n::translate('pages.status.unlisted'), 'unlisted', $unlisted);
}
2021-10-29 18:05:46 +02:00
2022-08-31 16:08:03 +02:00
if ($listed !== false) {
$sections['listed'] = $section(I18n::translate('pages.status.listed'), 'listed', $listed);
}
2021-10-29 18:05:46 +02:00
2022-08-31 16:08:03 +02:00
// cleaning up
unset($props['drafts'], $props['unlisted'], $props['listed'], $props['templates']);
2021-10-29 18:05:46 +02:00
2022-08-31 16:08:03 +02:00
return array_merge($props, ['sections' => $sections]);
2021-10-29 18:05:46 +02:00
};