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

Page.php - activeChild() throws error #3276

Closed
bkraegelin opened this issue Mar 16, 2021 · 1 comment
Closed

Page.php - activeChild() throws error #3276

bkraegelin opened this issue Mar 16, 2021 · 1 comment
Assignees

Comments

@bkraegelin
Copy link

While trying to implement modular pages within my module I came across an error thrown by Page.php:

“Call to a member function root() on null” on line 2508

The code is
2506 $child_page = $pages->find($uri->route())->parent();
2507 if ($child_page) {
2508 while (!$child_page->root()) {
2509 if ($this->path() === $child_page->path()) {
2510 return true;
2511 }
2512 $child_page = $child_page->parent();
2513 }
2514 }

Looking around I found a similar/nearly identical function activeChild() in /system/src/Grav/Common/Flex/Types/Pages/Traits/PageRoutableTrait.php with code
109 $child_page = $page ? $page->parent() : null;
110 while ($child_page && !$child_page->root()) {
111 if ($this->path() === $child_page->path()) {
112 return true;
113 }
114 $child_page = $child_page->parent();
115 }

After changing Page.php the error was gone. This may be incorporated into the code of Page.php.

Thanks, Birger

@rhukster
Copy link
Member

I think you should follow similar code to the PageRoutableTrait,

$child_page = $pages->find($uri->route())->parent() ?? null; 
while ($child_page && !$child_page->root()) {
...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants