Skip to content

Commit

Permalink
Add filter "filter" for CmsTwigExtension.
Browse files Browse the repository at this point in the history
  • Loading branch information
nilov authored Dec 2, 2016
1 parent 099793f commit 862bf3c
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions src/Extension/CmsTwigExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ public function getFunctions()
public function getFilters()
{
return [
new \Twig_SimpleFilter('content', [$this, 'content'])
new \Twig_SimpleFilter('content', [$this, 'content']),
new \Twig_SimpleFilter('filter', [$this, 'listFilter'])
];
}

Expand Down Expand Up @@ -173,7 +174,7 @@ public function isEditable()
$this->editable &&
$session->has('api_token') &&
$cmsRestClient->validateToken($session->get('api_token'))
;
;
}

/**
Expand Down Expand Up @@ -208,4 +209,24 @@ public function cmsAsset($resource)
{
return $this->cmsBaseUrl . '/' . $resource;
}
}

/**
* @param array $list
* @param array $filters
* @return array
*/
public function listFilter(array $list, array $filters)
{
return array_filter($list, function ($item) use ($filters) {
foreach ($filters as $filter) {
foreach ($filter as $filterName => $filterValue) {
if (!isset($item[$filterName]) || $item[$filterName] != $filterValue) {
return false;
}

return true;
}
}
});
}
}

0 comments on commit 862bf3c

Please sign in to comment.