commit 65906a5d7d08988634fa284fdd5bf3d9e89f8164
parent d1bae9818d3ddf4ad831496b798614c8c4366afa
Author: Jan Dankert <develop@jandankert.de>
Date: Mon, 11 Nov 2019 00:43:47 +0100
New: node settings could have config variables; macro settings could have settings variables.
Diffstat:
3 files changed, 41 insertions(+), 3 deletions(-)
diff --git a/modules/cms-core/model/BaseObject.class.php b/modules/cms-core/model/BaseObject.class.php
@@ -3,6 +3,7 @@
namespace cms\model;
+use ArrayUtils;
use cms\publish\Publish;
use phpseclib\Math\BigInteger;
use Spyc;
@@ -1333,10 +1334,20 @@ SQL
*/
public function getSettings()
{
- return Spyc::YAMLLoadString($this->settings);
+ $settings = Spyc::YAMLLoadString($this->settings);
+
+ // pass-by-reference
+ array_walk_recursive($settings, function (&$item, $key) {
+ $item = \Text::resolveVariables($item, 'config', function ($var) {
+ global $conf;
+ return ArrayUtils::getSubValue($conf,explode('.',$var) );
+ });
+ return $item;
+ });
+
+ return $settings;
}
-
/**
* Inherited Settings.
*
diff --git a/modules/cms-core/model/Value.class.php b/modules/cms-core/model/Value.class.php
@@ -1,5 +1,6 @@
<?php
namespace cms\model;
+use ArrayUtils;
use cms\publish\Publish;
use \ObjectNotFoundException;
use \Logger;
@@ -1299,7 +1300,16 @@ SQL
$macro->objectid = $this->page->objectid;
$macro->page = &$this->page;
- foreach( $this->element->getDynamicParameters() as $param_name=>$param_value )
+ $parameters = $this->element->getDynamicParameters();
+
+ array_walk_recursive($parameters, function (&$item, $key) {
+ $item = \Text::resolveVariables($item, 'setting', function ($var) {
+ return ArrayUtils::getSubValue($this->page->getSettings(),explode('.',$var) );
+ });
+ return $item;
+ });
+
+ foreach( $parameters as $param_name=>$param_value )
{
if ( $param_value[0]=='{')
{
diff --git a/modules/util/ArrayUtils.class.php b/modules/util/ArrayUtils.class.php
@@ -28,6 +28,23 @@ class ArrayUtils
+
+ public static function getSubValue( $array, $keys ) {
+
+ $a = $array;
+ foreach( $keys as $k )
+ {
+ if ( ! isset($a[$k]) )
+ return null;
+
+ $a = $a[$k];
+ }
+
+ return $a;
+ }
+
+
+
public static function flattenArray( $prefix, $arr, $split= '.' )
{
$new = array();