Skip to content

Commit a3a95e9

Browse files
committed
Fix page tree isParentOf var checking
1 parent 9453b69 commit a3a95e9

File tree

4 files changed

+15
-7
lines changed

4 files changed

+15
-7
lines changed

src/FlexibleContentBlockPagesPanel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public static function configurePanel(Panel $panel, ?string $id = null): Panel
3535
->plugin(SpatieLaravelTranslatablePlugin::make()
3636
->defaultLocales(FilamentFlexibleContentBlockPages::config()->getSupportedLocales()))
3737
->navigationItems(static::getExtraNavigationItems())
38-
->login(fn() => static::getLoginAction());
38+
->login(fn () => static::getLoginAction());
3939
}
4040

4141
/**

src/Models/Concerns/HasPageTreeTrait.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ public function hasParent(): bool
3333
return ! $this->isRoot();
3434
}
3535

36-
public function isParentOf(HasParent $child): bool
36+
public function isParentOf(HasParent&Model $child): bool
3737
{
38-
return property_exists($child, 'parent_id') && $this->id === $child->parent_id;
38+
return $child->hasAttribute('parent_id') && $this->id === $child->getAttribute('parent_id');
3939
}
4040
}

src/Resources/PageResource/Pages/ManagePageTree.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,15 @@ protected function getWithRelationQuery(): Builder
9393
{
9494
$query = parent::getWithRelationQuery();
9595
if (method_exists($this->getModel(), 'parent') && $this->getModel()::has('parent')) {
96-
return $query->with('parent');
96+
$treeDepth = FilamentFlexibleContentBlockPages::config()->getPageTreeMaximumDepth(FilamentFlexibleContentBlockPages::config()->getPageModel());
97+
$parentRelations = [];
98+
$parentRelation = '';
99+
while ($treeDepth-- > 0) {
100+
$parentRelation = 'parent'.(empty($parentRelation) ? '' : '.'.$parentRelation);
101+
$parentRelations[] = $parentRelation;
102+
}
103+
104+
return $query->with($parentRelations);
97105
}
98106

99107
return $query;

src/Services/SitemapGeneratorService.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,15 +215,15 @@ protected function getLinkableModels(): array
215215
return array_unique(array_merge($ctaModels, $menuModels));
216216
}
217217

218-
protected function calculatePriority(HasParent&HasCode $page): float
218+
protected function calculatePriority(HasParent&HasCode&Model $page): float
219219
{
220220
// Homepage gets highest priority
221-
if (property_exists($page, 'code') && $page->code === Page::HOME_PAGE) {
221+
if ($page->hasAttribute('code') && $page->getAttribute('code') === Page::HOME_PAGE) {
222222
return 1.0;
223223
}
224224

225225
// Parent pages get higher priority than children
226-
if (property_exists($page, 'parent_id') && ! $page->parent_id) {
226+
if ($page->hasAttribute('parent_id') && ! $page->getAttribute('parent_id')) {
227227
return 0.8;
228228
}
229229

0 commit comments

Comments
 (0)