Skip to content

Commit

Permalink
Merge pull request #56 from oveleon/develop
Browse files Browse the repository at this point in the history
Fix template variable for pages and layouts
  • Loading branch information
doishub authored Dec 20, 2021
2 parents e8981f8 + c068e1b commit 7475cf0
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Search for `oveleon/contao-component-style-manager` in the Contao Manager and ad

#### Manual installation
```
$ composer require oveleon/contao-component-style-manager
composer require oveleon/contao-component-style-manager
```

## Documentation
Expand Down
23 changes: 20 additions & 3 deletions src/Resources/contao/classes/StyleManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public static function clearClasses($varValue, $dc)

if(self::isMultipleField($dc->field))
{
$varValue = serialize(array($cssID[0] ?? '', $varValue));
$varValue = serialize(array(($cssID[0] ?? ''), $varValue));
}

return $varValue;
Expand Down Expand Up @@ -147,7 +147,7 @@ public static function updateClasses($varValue, $dc)

if(self::isMultipleField($dc->field))
{
$varValue = serialize(array($cssID[0] ?? '', $varValue));
$varValue = serialize(array(($cssID[0] ?? ''), $varValue));
}

return $varValue;
Expand Down Expand Up @@ -198,7 +198,7 @@ public static function resetClasses($varValue, $dc, $strTable)

if(self::isMultipleField($dc->field))
{
$varValue = serialize(array($cssID[0] ?? '', $varValue));
$varValue = serialize(array(($cssID[0] ?? ''), $varValue));
}

return $varValue;
Expand Down Expand Up @@ -376,6 +376,23 @@ 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
*
Expand Down
1 change: 1 addition & 0 deletions src/Resources/contao/config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

// 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');
Expand Down

0 comments on commit 7475cf0

Please sign in to comment.