Skip to content

Commit caec4e0

Browse files
authored
fix: PagePicker parent handling when same as start model (#7646)
fix: PagePicker parent handling when same as start model #7624 Prevents the parent option from being used in PagePicker if it is the same as the start/top-most model. Adds a test to verify correct behavior when query and parent refer to the same page.
1 parent 6243968 commit caec4e0

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

src/Cms/PagePicker.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,12 @@ public function items(): Pages|null
130130
// when subpage navigation is enabled, a parent
131131
// might be passed in addition to the query.
132132
// The parent then takes priority.
133-
} elseif ($this->options['subpages'] === true && empty($this->options['parent']) === false) {
133+
// Don't use the parent if it's the same as the start/top-most model.
134+
} elseif (
135+
$this->options['subpages'] === true &&
136+
empty($this->options['parent']) === false &&
137+
$this->model()->id() !== $this->start()->id()
138+
) {
134139
$items = $this->itemsForParent();
135140

136141
// search by query

tests/Cms/Page/PagePickerTest.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ public function setUp(): void
2222
[
2323
'slug' => 'mother',
2424
'children' => [
25-
['slug' => 'child-a'],
26-
['slug' => 'child-b'],
27-
['slug' => 'child-c']
25+
['slug' => 'child-a', 'template' => 'child-a'],
26+
['slug' => 'child-b', 'template' => 'child-b'],
27+
['slug' => 'child-c', 'template' => 'child-c']
2828
]
2929
]
3030
]
@@ -97,4 +97,16 @@ public function testQueryStart(): void
9797

9898
$this->assertSame('grandmother', $picker->start()->id());
9999
}
100+
101+
public function testSameQueryAndParent(): void
102+
{
103+
$picker = new PagePicker([
104+
'query' => 'site.find("grandmother/mother").children.filterBy("intendedTemplate", "in", ["child-a", "child-c"])',
105+
'parent' => 'grandmother/mother'
106+
]);
107+
108+
$this->assertCount(2, $picker->items());
109+
$this->assertSame('grandmother/mother/child-a', $picker->items()->first()->id());
110+
$this->assertSame('grandmother/mother/child-c', $picker->items()->last()->id());
111+
}
100112
}

0 commit comments

Comments
 (0)