ngrmm Posted May 19 Posted May 19 Page is moved after being unpublished via a hook. If you do on the page directly (settings tab) you have to click on the save button. This trigger a reload and everything is fine. But if you unpublish a page via the action button in the page tree view, there is no forced reload. Is there a way to force a refresh of the page tree via JS? $wire->addHookBefore('Pages::save', function($event) { $p = $event->arguments(0); if($p->template == 'funding_item') { // Disable output formatting $p->of(false); $newParent = wire('pages')->get(1234); $p->parent = $newParent; $p->save(); } }); UPDATE: I'm forcing it this way right now. But there should be a way to do it via AJAX as PW page tree is working on default. // config.php $config->scripts->add($config->urls->templates . "/scripts/_admin/pagetree_move.js"); // pagetree_move.js document.addEventListener("DOMContentLoaded", function() { const observer = new MutationObserver((mutationsList, observer) => { const unpublishButtons = document.querySelectorAll('.PageListTemplate_template_name a.PageListActionUnpublish'); unpublishButtons.forEach((btn) => { if (!btn.dataset.listenerAttached) { btn.dataset.listenerAttached = "true"; btn.addEventListener('click', function () { console.log('Unpublish clicked'); setTimeout(() => { location.reload(); }, 1000); }); } }); }); observer.observe(document.body, { childList: true, subtree: true, attributes: true }); });
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