diff --git a/src/Resources/contao/classes/StyleManager.php b/src/Resources/contao/classes/StyleManager.php index 20f2547..4ca5feb 100644 --- a/src/Resources/contao/classes/StyleManager.php +++ b/src/Resources/contao/classes/StyleManager.php @@ -376,23 +376,6 @@ public static function deserializeValues($arrValue){ return $arrValue; } - /** - * Adding template variables defined in pages and layouts - * - * @param $objPage - * @param $objLayout - * @param $page - */ - public function onGeneratePage($objPage, $objLayout, &$page) - { - $arrStyles = array_filter(array_merge_recursive( - StringUtil::deserialize($objPage->styleManager, true), - StringUtil::deserialize($objLayout->styleManager, true) - )); - - $page->Template->styleManager = serialize($arrStyles); - } - /** * Parse Template and set Variables * @@ -400,6 +383,20 @@ public function onGeneratePage($objPage, $objLayout, &$page) */ public function onParseTemplate($template) { + // Check page and template variables to pass them to the template + if(strpos($template->getName(), 'fe_page') === 0) + { + global $objPage; + + $arrStyles = array_filter(array_merge_recursive( + StringUtil::deserialize($objPage->styleManager, true), + StringUtil::deserialize($template->layout->styleManager, true) + )); + + $template->styleManager = serialize($arrStyles); + } + + // Build Styles object and assign it to the template if(!($template->styleManager instanceof Styles)) { $arrStyles = StringUtil::deserialize($template->styleManager); diff --git a/src/Resources/contao/classes/Styles.php b/src/Resources/contao/classes/Styles.php index fd087c8..d46504c 100644 --- a/src/Resources/contao/classes/Styles.php +++ b/src/Resources/contao/classes/Styles.php @@ -47,7 +47,7 @@ public function __construct($arrStyles=null) */ public function get($identifier, $arrGroups=null) { - if($this->styles === null || !is_array($this->styles[ $identifier ])) + if($this->styles === null || !is_array(($this->styles[ $identifier ] ?? null))) { return ''; } diff --git a/src/Resources/contao/config/config.php b/src/Resources/contao/config/config.php index 96d2c1a..6cdd8f1 100644 --- a/src/Resources/contao/config/config.php +++ b/src/Resources/contao/config/config.php @@ -31,7 +31,6 @@ // Hooks $GLOBALS['TL_HOOKS']['parseTemplate'][] = array('\\Oveleon\\ContaoComponentStyleManager\\StyleManager', 'onParseTemplate'); -$GLOBALS['TL_HOOKS']['generatePage'][] = array('\\Oveleon\\ContaoComponentStyleManager\\StyleManager', 'onGeneratePage'); $GLOBALS['TL_HOOKS']['loadFormField'][] = array('\\Oveleon\\ContaoComponentStyleManager\\StyleManager', 'onLoadFormField'); $GLOBALS['TL_HOOKS']['addCustomRegexp'][] = array('\\Oveleon\\ContaoComponentStyleManager\\StyleManager', 'addVariableRegexp'); $GLOBALS['TL_HOOKS']['executePostActions'][] = array('\\Oveleon\\ContaoComponentStyleManager\\Ajax', 'executePostActions');