Skip to content

Instantly share code, notes, and snippets.

@lukaskleinschmidt
Created October 23, 2020 08:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lukaskleinschmidt/729a7249ffe432d3f88c4a2d7fbab541 to your computer and use it in GitHub Desktop.
Save lukaskleinschmidt/729a7249ffe432d3f88c4a2d7fbab541 to your computer and use it in GitHub Desktop.
Add page models automatically in Kirby 3
<?php
use Kirby\Cms\App as Kirby;
use Kirby\Cms\Page;
use Kirby\Toolkit\A;
class DefaultPage extends Page
{
//
}
Kirby::plugin('domain/plugin', [
'hooks' => [
'system.loadPlugins:after' => function () {
$kirby = kirby();
$models = $kirby->extensions('pageModels');
$pages = A::pluck(site()->blueprints(), 'name');
// Patch pages that don't use a custom page model
$keys = array_filter($pages, function ($key) use ($models) {
return array_key_exists($key, $models) === false;
});
$kirby->extend([
'pageModels' => array_fill_keys($keys, DefaultPage::class),
]);
}
]
]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment