julienmonnerie/kirby/config/presets/pages.php

76 lines
1.3 KiB
PHP
Raw Normal View History

2022-06-17 17:51:59 +02:00
<?php
2022-08-31 15:02:43 +02:00
use Kirby\Toolkit\I18n;
2022-06-17 17:51:59 +02:00
2022-08-31 15:02:43 +02:00
return function (array $props) {
// load the general templates setting for all sections
$templates = $props['templates'] ?? null;
2022-06-17 17:51:59 +02:00
2022-12-19 14:56:05 +01:00
$section = function ($label, $status, $props) use ($templates) {
2022-08-31 15:02:43 +02:00
$defaults = [
2022-12-19 14:56:05 +01:00
'label' => $label,
'type' => 'pages',
'layout' => 'list',
'status' => $status
2022-08-31 15:02:43 +02:00
];
2022-06-17 17:51:59 +02:00
2022-08-31 15:02:43 +02:00
if ($props === true) {
$props = [];
}
2022-06-17 17:51:59 +02:00
2022-08-31 15:02:43 +02:00
if (is_string($props) === true) {
$props = [
2022-12-19 14:56:05 +01:00
'label' => $props
2022-08-31 15:02:43 +02:00
];
}
2022-06-17 17:51:59 +02:00
2022-08-31 15:02:43 +02:00
// inject the global templates definition
if (empty($templates) === false) {
2025-04-21 18:57:21 +02:00
$props['templates'] ??= $templates;
2022-08-31 15:02:43 +02:00
}
2022-06-17 17:51:59 +02:00
2022-08-31 15:02:43 +02:00
return array_replace_recursive($defaults, $props);
};
2022-06-17 17:51:59 +02:00
2022-08-31 15:02:43 +02:00
$sections = [];
2022-06-17 17:51:59 +02:00
2022-08-31 15:02:43 +02:00
$drafts = $props['drafts'] ?? [];
$unlisted = $props['unlisted'] ?? false;
$listed = $props['listed'] ?? [];
2022-06-17 17:51:59 +02:00
2022-08-31 15:02:43 +02:00
if ($drafts !== false) {
2025-07-11 14:41:34 +02:00
$sections['drafts'] = $section(
I18n::translate('pages.status.draft'),
'drafts',
$drafts
);
2022-08-31 15:02:43 +02:00
}
2022-06-17 17:51:59 +02:00
2022-08-31 15:02:43 +02:00
if ($unlisted !== false) {
2025-07-11 14:41:34 +02:00
$sections['unlisted'] = $section(
I18n::translate('pages.status.unlisted'),
'unlisted',
$unlisted
);
2022-08-31 15:02:43 +02:00
}
2022-06-17 17:51:59 +02:00
2022-08-31 15:02:43 +02:00
if ($listed !== false) {
2025-07-11 14:41:34 +02:00
$sections['listed'] = $section(
I18n::translate('pages.status.listed'),
'listed',
$listed
);
2022-08-31 15:02:43 +02:00
}
2022-06-17 17:51:59 +02:00
2022-08-31 15:02:43 +02:00
// cleaning up
2025-07-11 14:41:34 +02:00
unset(
$props['drafts'],
$props['unlisted'],
$props['listed'],
$props['templates']
);
2022-06-17 17:51:59 +02:00
2025-07-11 14:41:34 +02:00
return [...$props, 'sections' => $sections];
2022-06-17 17:51:59 +02:00
};