From c7c234d04afb61fa0bbdbec625c975de24ef3e38 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Fri, 11 Aug 2017 11:17:05 -0600 Subject: [PATCH] Added `array_key_exists` wrapper function --- CHANGELOG.md | 1 + system/src/Grav/Common/Twig/TwigExtension.php | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5efa8e180..7cf03688e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ * Added a new `clear_images_by_default` system property to stop cache clear events from removing processed images [#1481](https://github.com/getgrav/grav/pull/1481) * Added new `onTwigLoader()` event to enable utilization of loader methods * Added new `Twig::addPath()` and `Twig::prependPath()` methods to wrap loader methods and support namespacing [#1604](https://github.com/getgrav/grav/issues/1604) + * Added new `array_key_exists()` Twig function wrapper 1. [](#bugfix) * Allow `session.timetout` field to be set to `0` via blueprints [#1598](https://github.com/getgrav/grav/issues/1598) diff --git a/system/src/Grav/Common/Twig/TwigExtension.php b/system/src/Grav/Common/Twig/TwigExtension.php index 908b5fdac..a5575e26f 100644 --- a/system/src/Grav/Common/Twig/TwigExtension.php +++ b/system/src/Grav/Common/Twig/TwigExtension.php @@ -107,6 +107,7 @@ class TwigExtension extends \Twig_Extension return [ new \Twig_SimpleFunction('array', [$this, 'arrayFunc']), new \Twig_SimpleFunction('array_key_value', [$this, 'arrayKeyValueFunc']), + new \Twig_SimpleFunction('array_key_exists', [$this, 'arrayKeyExistsFunc']), new \Twig_simpleFunction('authorize', [$this, 'authorize']), new \Twig_SimpleFunction('debug', [$this, 'dump'], ['needs_context' => true, 'needs_environment' => true]), new \Twig_SimpleFunction('dump', [$this, 'dump'], ['needs_context' => true, 'needs_environment' => true]), @@ -818,6 +819,19 @@ class TwigExtension extends \Twig_Extension } } + /** + * Check to see if an array key exists + * + * @param string $key key of item + * @param string $current_array optional array to add to + * + * @return array + */ + public function arrayKeyExistsFunc($key, $current_array = null) + { + return array_key_exists($key, $current_array); + } + /** * Returns a string from a value. If the value is array, return it json encoded *