Created
March 26, 2015 01:44
#concrete5 #concrete56 Set the page's theme same as parent's theme on writing with composer
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 | |
// 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