Remove Pico's map Twig filter

Fixes #623
This commit is contained in:
Daniel Rudolf 2022-03-21 01:49:27 +01:00
parent 6698130b0f
commit 1da5e26d57
No known key found for this signature in database
GPG key ID: A061F02CD8DE4538
2 changed files with 2 additions and 33 deletions

View file

@ -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

View file

@ -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
*