Created
October 23, 2020 08:35
-
-
Save lukaskleinschmidt/729a7249ffe432d3f88c4a2d7fbab541 to your computer and use it in GitHub Desktop.
Add page models automatically in Kirby 3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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