Added custom header. query type with default support

This commit is contained in:
Andy Miller
2015-01-09 13:26:18 -07:00
parent dc0b7cd3d2
commit f48a05e247
2 changed files with 31 additions and 1 deletions

View File

@@ -0,0 +1,11 @@
<?php
namespace Grav\Common\Page;
use RocketTheme\Toolbox\ArrayTraits\Constructor;
use RocketTheme\Toolbox\ArrayTraits\NestedArrayAccess;
class Header implements \ArrayAccess
{
use NestedArrayAccess, Constructor;
}

View File

@@ -597,6 +597,16 @@ class Pages
protected function buildSort($path, array $pages, $order_by = 'default', $manual = null)
{
$list = array();
$header_default = null;
$header_query = null;
// do this headery query work only once
if (strpos($order_by, 'header.') === 0) {
$header_query = explode('|', str_replace('header.', '', $order_by));
if (isset($header_query[1])) {
$header_default = $header_query[1];
}
}
foreach ($pages as $key => $info) {
@@ -616,11 +626,20 @@ class Pages
$list[$key] = $child->modified();
break;
case 'slug':
$list[$key] = $info['slug'];
$list[$key] = $child->slug();
break;
case 'basename':
$list[$key] = basename($key);
break;
case (is_string($header_query[0])):
$child_header = new Header((array)$child->header());
$header_value = $child_header->get($header_query[0]);
if ($header_value) {
$list[$key] = $header_value;
} else {
$list[$key] = $header_default ?: $key;
}
break;
case 'manual':
case 'default':
default: