Jump to content

Recommended Posts

Posted

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   
	});
});

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...