Jump to content

Recommended Posts

Posted

Hi,

a question of a hook newbie... Probably a simple one, but nonetheless i don't get it after reading the docs and playing around.

While in admin i do something with some page fields before saving a page (here: generating vcards). If the page already exists (e.g. edit the page), its straight forward:

$wire->addHookBefore('Pages::saveReady', function($event){
	$page = $event->arguments(0);
	// do something with some $page fields...
});

But i forgot to handle the case when a page is added. This naturally this leads to a

ProcessPageAdd: New page '/path/to/page' must be saved before files can be accessed from it

For my understanding, i somehow must differ between Pages::added and Pages::save (or Pages::saveReady) and/or combine the two respectively.  Anyway, i assume this may not quite right, so i am running out of ideas. Maybe someone could give me some advice how this should be done.

Thx in advance!

Posted

Perhaps you can just run your code after saving?

$wire->addHookAfter("Pages::saved", /* … */);

Also worth noting is the hook Pages::savedPageOrField.

  • Like 2
Posted

If you want to do something if the page has not yet been created:

if(!$page->id) {
	// Do something here
}

 

 

  • Like 2

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
×
×
  • Create New...