PawelGIX Posted November 25, 2025 Posted November 25, 2025 (edited) I'm looking for a solution that would allow me to hide some templates from the tree list in the admin and modify the Children number to the correct value. Is there such a hook? I would also like it to work for superuser. I tried couple of them like ProcessPageList::find or ProcessPageListRenderJSON::execute but without luck. Update: I managed to achieve what I wanted, but to do it I had to use two separate hooks. $wire->addHookAfter('ProcessPageListRender::getNumChildren', function (HookEvent $event) { $user = $event->wire()->user; $username = $user->name; if ($username !== FULL_PAGE_TREE_USERNAME) { $page = $event->arguments(0); $return = $event->return; $return = $page->numChildren('template!=category|board-category, include=all'); $event->return = $return; } }); $wire->addHookAfter('ProcessPageList::find', function (HookEvent $event) { // Get the user $user = $event->wire()->user; $username = $user->name; if ($username !== FULL_PAGE_TREE_USERNAME) { $event->return->each(function ($p) use ($event) { if ($p->template == 'material-group') $event->return->remove($p); if ($p->template == 'board-category') $event->return->remove($p); if ($p->template == 'category') $event->return->remove($p); return; }); } }); I hope it doesn't have any side effects. If there's a better method, I'd love to know about it 😉 Edited November 25, 2025 by PawelGIX Working solution
monollonom Posted November 25, 2025 Posted November 25, 2025 Have you tried ProcessPageList::getSelector?
PawelGIX Posted November 25, 2025 Author Posted November 25, 2025 After adding to ready.php this code nothing was logged. $wire->addHookBefore('ProcessPageLister::getSelector', function(HookEvent $event) { // Get the object the event occurred on, if needed $ProcessPageLister = $event->object; bd($event, '$arguments'); });
monollonom Posted November 25, 2025 Posted November 25, 2025 Sorry I made a typo in the URL it’s ProcessPageList::getSelector (and not ProcessPageLister::getSelector), my bad
PawelGIX Posted November 25, 2025 Author Posted November 25, 2025 (edited) It works but does not affect the number of children displayed. So there is a discrepancy between what you see in the tree and the number next to it. Edited November 25, 2025 by PawelGIX
taotoo Posted November 26, 2025 Posted November 26, 2025 Here is what I did - or rather what AI did for me... I don't know if it's better or worse than your code though. Spoiler # ================================================================================ # PAGE TREE: HIDE ALL PAGES FROM CLIENT # WHERE THE PAGE TEMPLATE STARTS "PB-" # ================================================================================ $this->addHookAfter('ProcessPageList::find', function (HookEvent $event) { if ($this->wire('user')->isSuperuser()) { return; // Don't execute for superusers } $pbTemplates = $this->wire('templates')->find("name^=pb-"); $pbTemplateNames = []; foreach ($pbTemplates as $template) { $pbTemplateNames[] = $template->name; } if (!empty($pbTemplateNames)) { $event->return->find([ "template" => $pbTemplateNames, // Pages with 'pb-' templates ])->each(function($p) use ($event) { $event->return->remove($p); }); } }); # ================================================================================ # PAGE TREE: RECALCULATE # OF PAGES PER BRANCH # SO THAT # DISPLAYED IS CORRECT, AND DROPDOWN # CHEVRONS ONLY APPEAR WHEN NECESSARY # ================================================================================ $wire->addHookBefore('ProcessPageListRender::getNumChildren', function(HookEvent $event) { if ($this->wire('user')->isSuperuser()) { return; // Don't execute for superusers } $allTemplates = $this->wire('templates'); $pbTemplates = $this->wire('templates')->find("name^=pb-"); $pbTemplateNames = []; foreach ($pbTemplates as $template) { $pbTemplateNames[] = $template->name; } $allTemplateNames = []; foreach ($allTemplates as $template) { $allTemplateNames[] = $template->name; } $allowed_templates = array_diff($allTemplateNames, $pbTemplateNames); $event->wire; $selector = 'template=' . implode('|', $allowed_templates); $event->arguments(1, $selector); });
bernhard Posted November 26, 2025 Posted November 26, 2025 As far as I know what you did is still the best solution: https://github.com/processwire/processwire-issues/issues/649
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now