From 1bfe99b9cd100edeb9e807dd1bf9a04218c7c7a3 Mon Sep 17 00:00:00 2001 From: Djamil Legato Date: Sat, 27 Aug 2016 12:29:11 -0700 Subject: [PATCH] Allow `Utils::setDotNotation` to merge data, rather than just set. --- CHANGELOG.md | 1 + system/src/Grav/Common/Utils.php | 19 ++++++++++++++----- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6b60d93fc..5ff1192b4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ * Added support for `self@`, `page@`, `taxonomy@`, `root@` Collection syntax for cleaner YAML compatibility * Improved GPM commands to allow for `-y` to automate **yes** responses and `-o` for **update** and **selfupgrade** to overwrite installations [#985](https://github.com/getgrav/grav/issues/985) * Added randomization to `safe_email` Twig filter for greater security [#998](https://github.com/getgrav/grav/issues/998) + * Allow `Utils::setDotNotation` to merge data, rather than just set 1. [](#bugfix) * Removed 307 redirect code option as it is not well supported [#743](https://github.com/getgrav/grav-plugin-admin/issues/743) * Fixed issue with folders with name `*.md` are not confused with pages [#995](https://github.com/getgrav/grav/issues/995) diff --git a/system/src/Grav/Common/Utils.php b/system/src/Grav/Common/Utils.php index f18dd37b8..b8718ebfc 100644 --- a/system/src/Grav/Common/Utils.php +++ b/system/src/Grav/Common/Utils.php @@ -711,12 +711,14 @@ abstract class Utils * Set portion of array (passed by reference) for a dot-notation key * and set the value * - * @param $array - * @param $key - * @param $value + * @param $array + * @param $key + * @param $value + * @param bool $merge + * * @return mixed */ - public static function setDotNotation(&$array, $key, $value) + public static function setDotNotation(&$array, $key, $value, $merge = false) { if (is_null($key)) return $array = $value; @@ -734,7 +736,14 @@ abstract class Utils $array =& $array[$key]; } - $array[array_shift($keys)] = $value; + $key = array_shift($keys); + + if (!$merge || !isset($array[$key])) { + $array[$key] = $value; + } else { + $array[$key] = array_merge($array[$key], $value); + } + return $array; }