Skip to content

Commit

Permalink
Fixed page search not working with selected language [#3316]
Browse files Browse the repository at this point in the history
  • Loading branch information
mahagr committed Mar 25, 2022
1 parent b0add67 commit 5a355fb
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
3. [](#bugfix)
* Fixed issue with `system.cache.gzip: true` resulted in "Fetch Failed" for PHP 8.0.17 and PHP 8.1.4 [PHP issue #8218](https://github.com/php/php-src/issues/8218)
* Fix for multi-lang issues with Security Report
* Fixed page search not working with selected language [#3316](https://github.com/getgrav/grav/issues/3316)

# v1.7.31
## 03/14/2022
Expand Down
7 changes: 2 additions & 5 deletions system/src/Grav/Common/Flex/Types/Pages/PageIndex.php
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ protected function translateEntries(array $entries, string $lang, bool $fallback
continue;
}

// Get the main key without template and langauge.
// Get the main key without template and language.
[$main_key,] = explode('|', $entry['storage_key'] . '|', 2);

// Update storage key and language.
Expand Down Expand Up @@ -527,10 +527,7 @@ protected function getLevelListingRecurse(array $options): array
$language = $options['lang'];

$status = 'error';
$msg = null;
$response = [];
$children = null;
$sub_route = null;
$extra = null;

// Handle leaf_route
Expand Down Expand Up @@ -610,7 +607,7 @@ protected function getLevelListingRecurse(array $options): array
$children = $page->children();
/** @var PageIndex $children */
$children = $children->getIndex();
$selectedChildren = $children->filterBy($filters, true);
$selectedChildren = $children->filterBy($filters + ['language' => $language], true);

/** @var Header $header */
$header = $page->header();
Expand Down
28 changes: 18 additions & 10 deletions system/src/Grav/Common/Flex/Types/Pages/PageObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -586,38 +586,46 @@ public function getLevelListing(array $options): array
*/
public function filterBy(array $filters, bool $recursive = false): bool
{
$language = $filters['language'] ?? null;
if (null !== $language) {
/** @var PageObject $test */
$test = $this->getTranslation($language) ?? $this;
} else {
$test = $this;
}

foreach ($filters as $key => $value) {
switch ($key) {
case 'search':
$matches = $this->search((string)$value) > 0.0;
$matches = $test->search((string)$value) > 0.0;
break;
case 'page_type':
$types = $value ? explode(',', $value) : [];
$matches = in_array($this->template(), $types, true);
$matches = in_array($test->template(), $types, true);
break;
case 'extension':
$matches = Utils::contains((string)$value, $this->extension());
$matches = Utils::contains((string)$value, $test->extension());
break;
case 'routable':
$matches = $this->isRoutable() === (bool)$value;
$matches = $test->isRoutable() === (bool)$value;
break;
case 'published':
$matches = $this->isPublished() === (bool)$value;
$matches = $test->isPublished() === (bool)$value;
break;
case 'visible':
$matches = $this->isVisible() === (bool)$value;
$matches = $test->isVisible() === (bool)$value;
break;
case 'module':
$matches = $this->isModule() === (bool)$value;
$matches = $test->isModule() === (bool)$value;
break;
case 'page':
$matches = $this->isPage() === (bool)$value;
$matches = $test->isPage() === (bool)$value;
break;
case 'folder':
$matches = $this->isPage() === !$value;
$matches = $test->isPage() === !$value;
break;
case 'translated':
$matches = $this->hasTranslation() === (bool)$value;
$matches = $test->hasTranslation() === (bool)$value;
break;
default:
$matches = true;
Expand Down

0 comments on commit 5a355fb

Please sign in to comment.