aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorVictor Häggqvist <[email protected]>2016-01-27 00:58:22 +0100
committerVictor Häggqvist <[email protected]>2016-01-27 01:19:59 +0100
commit9590f61229a6e23c4f4ed91d34e3224804f69d40 (patch)
tree69947d6fe15362a066594169f7e7d7dba2904595 /src
parent35b7217cab4ac9ebae1a757b06cfaaae40a8e670 (diff)
add doctrine collection support
Diffstat (limited to 'src')
-rw-r--r--src/SortByFieldExtension.php7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/SortByFieldExtension.php b/src/SortByFieldExtension.php
index 5241b9e..0eda94a 100644
--- a/src/SortByFieldExtension.php
+++ b/src/SortByFieldExtension.php
@@ -31,8 +31,15 @@ class SortByFieldExtension extends \Twig_Extension {
* Usage: {% for entry in master.entries|sortbyfield('ordering', 'desc') %}
*/
public function sortByFieldFilter($content, $sort_by = null, $direction = 'asc') {
+
+ if (is_a($content, 'Doctrine\Common\Collections\Collection')) {
+ $content = $content->toArray();
+ }
+
if (!is_array($content)) {
throw new \InvalidArgumentException('Variable passed to the sortByField filter is not an array');
+ } elseif (count($content) < 1) {
+ return $content;
} elseif ($sort_by === null) {
throw new Exception('No sort by parameter passed to the sortByField filter');
} elseif (!self::isSortable(current($content), $sort_by)) {