Skip to content

Commit

Permalink
Added new Collection::toExtendedArray()
Browse files Browse the repository at this point in the history
  • Loading branch information
rhukster committed Jan 25, 2018
1 parent 103ac4b commit 47746d3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# v1.4.0-rc.2
## mm/dd/2018

1. [](#new)
* Added new `Collection:toExtendedArray()` method that's particularly useful for Json output of data
1. [](#improved)
* Better `Page.collection()` filtering support including ability to have non-published pages in collections

Expand Down
19 changes: 19 additions & 0 deletions system/src/Grav/Common/Page/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -610,4 +610,23 @@ public function ofOneOfTheseAccessLevels($accessLevels)

return $this;
}

/**
* Get the extended version of this Collection with each page keyed by route
*
* @return array
* @throws \Exception
*/
public function toExtendedArray()
{
$items = [];
foreach ($this->items as $path => $slug) {
$page = $this->pages->get($path);

if ($page !== null) {
$items[$page->route()] = $page->toArray();
}
}
return $items;
}
}

0 comments on commit 47746d3

Please sign in to comment.