Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include drafts in finding pages key recursively #6354

Draft
wants to merge 1 commit into
base: develop-minor
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Cms/Pages.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ protected function findByKeyRecursive(
$query = $startAt;

foreach ($path as $key) {
$collection = $item?->children() ?? $this;
$collection = $item?->childrenAndDrafts() ?? $this;
$query = ltrim($query . '/' . $key, '/');
$item = $collection->get($query) ?? null;

Expand Down
44 changes: 44 additions & 0 deletions tests/Cms/Pages/PagesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,50 @@ public function testFindChildrenWithSwappedSlugsTranslated()
$this->assertIsPage('zzz/yyy', $pages->find('zzz/yyy'));
}

public function testFindChildrenDrafts()
{
$app = new App([
'roots' => [
'index' => '/dev/null'
],
'site' => [
'children' => [
[
'slug' => 'grand',
'children' => [
[
'slug' => 'mother',
'children' => [
[
'slug' => 'child',
]
]
]
],
'drafts' => [
[
'slug' => 'father',
'children' => [
[
'slug' => 'child',
]
]
]
]
]
]
]
]);

$site = $app->site();

$this->assertIsPage('grand', $site->children()->find('grand'));
$this->assertIsPage('grand/mother', $site->children()->find('grand/mother'));
$this->assertIsPage('grand/father', $site->children()->find('grand/father'));
$this->assertIsPage('grand/mother/child', $site->children()->find('grand/mother/child'));
$this->assertIsPage('grand/father/child', $site->children()->find('grand/father/child'));
}

public function testFindMultiple()
{
$pages = Pages::factory([
Expand Down
Loading