From 8c00a0bc00f1921e55fd2e320feed2654a817111 Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Wed, 10 Feb 2021 10:58:17 +0200 Subject: [PATCH] Fixed behavior of opposite filters in `Pages::getCollection()` to match Grav 1.6 [#3216] --- CHANGELOG.md | 1 + system/src/Grav/Common/Page/Pages.php | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c335f90e6..ff2241839 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ * Fixed pipelined asset using different hash when extra asset is added to before/after position [#2781](https://github.com/getgrav/grav/issues/2781) * Fixed trailing slash redirect to only apply to GET/HEAD requests and use 301 status code [#3127](https://github.com/getgrav/grav/issues/3127) * Fixed `` to use name instead property [#3010](https://github.com/getgrav/grav/pull/3010) + * Fixed behavior of opposite filters in `Pages::getCollection()` to match Grav 1.6 [#3216](https://github.com/getgrav/grav/pull/3216) # v1.7.5 ## 02/01/2021 diff --git a/system/src/Grav/Common/Page/Pages.php b/system/src/Grav/Common/Page/Pages.php index c4e6cf724..0c430fd5d 100644 --- a/system/src/Grav/Common/Page/Pages.php +++ b/system/src/Grav/Common/Page/Pages.php @@ -459,14 +459,24 @@ class Pages // Remove any inclusive sets from filter. $sets = ['published', 'visible', 'modular', 'routable']; foreach ($sets as $type) { - $var = "non-{$type}"; - if (isset($filters[$type], $filters[$var]) && $filters[$type] && $filters[$var]) { - unset($filters[$type], $filters[$var]); + $nonType = "non-{$type}"; + if (isset($filters[$type], $filters[$nonType]) && $filters[$type] === $filters[$nonType]) { + if (!$filters[$type]) { + // Both options are false, return empty collection as nothing can match the filters. + return new Collection(); + } + + // Both options are true, remove opposite filters as all pages will match the filters. + unset($filters[$type], $filters[$nonType]); } } // Filter the collection foreach ($filters as $type => $filter) { + if (null === $filter) { + continue; + } + // Convert non-type to type. if (str_starts_with($type, 'non-')) { $type = substr($type, 4);