Skip to content

Instantly share code, notes, and snippets.

@hissy
Created March 26, 2015 01:44
#concrete5 #concrete56 Set the page's theme same as parent's theme on writing with composer
<?php
// config/site_events.php
defined('C5_EXECUTE') or die("Access Denied.");
Events::extend('on_composer_save_draft', 'ComposerCustomize', 'changeToParentsTheme', __FILE__);
class ComposerCustomize
{
public function changeToParentsTheme($entry)
{
if ($entry instanceof ComposerPage) {
$ct = CollectionType::getByID($entry->getCollectionTypeID());
if ($ct->getCollectionTypeComposerPublishMethod() == 'CHOOSE' || $ct->getCollectionTypeComposerPublishMethod() == 'PAGE_TYPE') {
$parent = Page::getByID($entry->getComposerDraftPublishParentID());
} else if ($ct->getCollectionTypeComposerPublishMethod() == 'PARENT') {
$parent = Page::getByID($ct->getCollectionTypeComposerPublishPageParentID());
}
if (is_object($parent)) {
$parentTheme = $parent->getCollectionThemeObject();
$entry->setTheme($parentTheme);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment