Something I’ve hit a few times, and I had to try and solve today, is an issue when you’re creating a new page through Composer and a site has multiple themes installed.
What happens is that the newly created page (draft) defaults to the active theme. Makes sense.
But I’ve hit times where that’s not what you want, and you have to then manually change the theme over for the page every time you create it. There can be quite a few different reasons for having multiple themes installed: different parts of a site, public/private areas, etc, and sometimes you might have combinations of page types meant to be used with different themes.
What I’m wondering is whether something against a Page Type configuration that allows you to define the theme to use when creating the page is missing. Such a setting could have as a default option ‘Active Theme’ (so it behaves as it does now), or, you could pick specifically one of the installed themes.
Today I had to solve this with a simple additional add-on with an on_start function like this:
public function on_start()
{
Events::addListener('on_page_add', function($event) {
$page = $event->getPageObject();
if ($page->getPageTypeHandle() == 'property') {
$theme = Theme::getByHandle('custom_theme');
if ($theme) {
$page->setTheme($theme);
}
}
});
}
That does the job, and fires as the page is initially created, but it a bit of a hardcoded solution.
So I’m wondering if I’m overlooking some setting somewhere, or whether I should look to create a pull request where there’s another setting against Page Types to control the theme.