parent
6698130b0f
commit
1da5e26d57
2 changed files with 2 additions and 33 deletions
|
@ -54,6 +54,8 @@ Released: -
|
||||||
* [Fixed] #602: Fix contents and meta data of meta pages (pages starting with
|
* [Fixed] #602: Fix contents and meta data of meta pages (pages starting with
|
||||||
an `_`) getting replaced by the 404 page when being requested
|
an `_`) getting replaced by the 404 page when being requested
|
||||||
* [Fixed] Add a proper error message for a missing theme directory
|
* [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
|
### Version 3.0.0-alpha.2
|
||||||
|
|
|
@ -81,7 +81,6 @@ class PicoTwigExtension extends AbstractTwigExtension
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'markdown' => new TwigFilter('markdown', [ $this, 'markdownFilter' ], [ 'is_safe' => [ 'html' ] ]),
|
'markdown' => new TwigFilter('markdown', [ $this, 'markdownFilter' ], [ 'is_safe' => [ 'html' ] ]),
|
||||||
'map' => new TwigFilter('map', [ $this, 'mapFilter' ]),
|
|
||||||
'sort_by' => new TwigFilter('sort_by', [ $this, 'sortByFilter' ]),
|
'sort_by' => new TwigFilter('sort_by', [ $this, 'sortByFilter' ]),
|
||||||
'link' => new TwigFilter('link', [ $this->pico, 'getPageUrl' ]),
|
'link' => new TwigFilter('link', [ $this->pico, 'getPageUrl' ]),
|
||||||
'url' => new TwigFilter('url', [ $this->pico, 'substituteUrl' ]),
|
'url' => new TwigFilter('url', [ $this->pico, 'substituteUrl' ]),
|
||||||
|
@ -127,38 +126,6 @@ class PicoTwigExtension extends AbstractTwigExtension
|
||||||
return $this->getPico()->parseFileContent($markdown, $singleLine);
|
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
|
* Sorts an array by one of its keys or a arbitrary deep sub-key
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue