Skip to content

Commit

Permalink
feat: add hidePageFromTree method
Browse files Browse the repository at this point in the history
  • Loading branch information
BernhardBaumrock committed Apr 18, 2024
1 parent 688a69e commit e8c6681
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions RockMigrations.module.php
Original file line number Diff line number Diff line change
Expand Up @@ -2040,6 +2040,23 @@ private function hideFromGuests(): void
);
}

/**
* Hide given page from pagetree and adjust numchildren count
* @param mixed $page
* @return void
*/
public function hidePageFromTree($page): void
{
$page = $this->wire->pages->get((string)$page);
$this->addHookAfter("ProcessPageList::find", function (HookEvent $event) use ($page) {
$event->return->remove($page);
});
$this->addHookBefore('ProcessPageListRender::getNumChildren', function (HookEvent $event) use ($page) {
$p = $event->arguments(0);
if ($p->id === $page->parent->id) $p->numChildren = $p->numChildren - 1;
});
}

/**
* Actions to perform on modules refresh
*/
Expand Down

0 comments on commit e8c6681

Please sign in to comment.