From 1da5e26d57fafb023782f86ffe5ce9211762b04a Mon Sep 17 00:00:00 2001 From: Daniel Rudolf Date: Mon, 21 Mar 2022 01:49:27 +0100 Subject: [PATCH] Remove Pico's `map` Twig filter Fixes #623 --- CHANGELOG.md | 2 ++ lib/PicoTwigExtension.php | 33 --------------------------------- 2 files changed, 2 insertions(+), 33 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d4c4878..8162bf7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -54,6 +54,8 @@ Released: - * [Fixed] #602: Fix contents and meta data of meta pages (pages starting with an `_`) getting replaced by the 404 page when being requested * [Fixed] Add a proper error message for a missing theme directory +* [Removed] ! Remove Pico's `map` Twig filter; it conflicts with Twig's `map` + filter and can be replaced by Twig's `column` or `map` filter ``` ### Version 3.0.0-alpha.2 diff --git a/lib/PicoTwigExtension.php b/lib/PicoTwigExtension.php index f85dc86..428dc03 100644 --- a/lib/PicoTwigExtension.php +++ b/lib/PicoTwigExtension.php @@ -81,7 +81,6 @@ class PicoTwigExtension extends AbstractTwigExtension { return [ 'markdown' => new TwigFilter('markdown', [ $this, 'markdownFilter' ], [ 'is_safe' => [ 'html' ] ]), - 'map' => new TwigFilter('map', [ $this, 'mapFilter' ]), 'sort_by' => new TwigFilter('sort_by', [ $this, 'sortByFilter' ]), 'link' => new TwigFilter('link', [ $this->pico, 'getPageUrl' ]), 'url' => new TwigFilter('url', [ $this->pico, 'substituteUrl' ]), @@ -127,38 +126,6 @@ class PicoTwigExtension extends AbstractTwigExtension return $this->getPico()->parseFileContent($markdown, $singleLine); } - /** - * Returns a array with the values of the given key or key path - * - * This method is registered as the Twig `map` filter. You can use this - * filter to e.g. get all page titles (`{{ pages|map("title") }}`). - * - * @param array|Traversable $var variable to map - * @param mixed $mapKeyPath key to map; either a scalar or a - * array interpreted as key path (i.e. ['foo', 'bar'] will return all - * $item['foo']['bar'] values) - * - * @return array mapped values - * - * @throws TwigRuntimeError - */ - public function mapFilter($var, $mapKeyPath): array - { - if (!is_array($var) && (!is_object($var) || !($var instanceof Traversable))) { - throw new TwigRuntimeError(sprintf( - 'The map filter only works with arrays or "Traversable", got "%s"', - is_object($var) ? get_class($var) : gettype($var) - )); - } - - $result = []; - foreach ($var as $key => $value) { - $mapValue = $this->getKeyOfVar($value, $mapKeyPath); - $result[$key] = ($mapValue !== null) ? $mapValue : $value; - } - return $result; - } - /** * Sorts an array by one of its keys or a arbitrary deep sub-key *