Skip to content

Commit

Permalink
Better fix for #2750
Browse files Browse the repository at this point in the history
  • Loading branch information
rhukster committed Dec 4, 2019
1 parent 3e8572d commit e842eb9
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions system/src/Grav/Common/Page/Pages.php
Original file line number Diff line number Diff line change
Expand Up @@ -1266,11 +1266,9 @@ protected function buildSort($path, array $pages, $order_by = 'default', $manual
$header_query = [];

// do this header query work only once
if (strpos($order_by, 'header.') === 0) {
if (Utils::startsWith($order_by, 'header.')) {
$header_query = explode('|', str_replace('header.', '', $order_by));
if (isset($header_query[1])) {
$header_default = $header_query[1];
}
$header_default = $header_query[1] ?? null;
}

foreach ($pages as $key => $info) {
Expand Down Expand Up @@ -1308,23 +1306,28 @@ protected function buildSort($path, array $pages, $order_by = 'default', $manual
case 'folder':
$list[$key] = $child->folder();
break;
case (isset($header_query[0]) && is_string($header_query[0])):
$child_header = new Header((array)$child->header());
$header_value = $child_header->get($header_query[0]);
if (is_array($header_value)) {
$list[$key] = implode(',',$header_value);
} elseif ($header_value) {
$list[$key] = $header_value;
} else {
$list[$key] = $header_default ?: $key;
}
$sort_flags = $sort_flags ?: SORT_REGULAR;
break;
case 'header':
case 'manual':
case 'default':
default:
$list[$key] = $key;
$sort_flags = $sort_flags ?: SORT_REGULAR;
if (Utils::startsWith($order_by, 'header.')) {
$child_header = new Header((array)$child->header());
if (isset($header_query) && is_array($header_query)) {
$header_value = $child_header->get($header_query[0]);
if (is_array($header_value)) {
$list[$key] = implode(',',$header_value);
} elseif ($header_value) {
$list[$key] = $header_value;
} else {
$list[$key] = $header_default ?: $key;
}
}
$sort_flags = $sort_flags ?: SORT_REGULAR;
break;
} else {
$list[$key] = $key;
$sort_flags = $sort_flags ?: SORT_REGULAR;
}
}
}

Expand Down

0 comments on commit e842eb9

Please sign in to comment.