Jump to content

Recommended Posts

Posted

Hi all

I have the hook written below... and it works fine on pages that have already been created (when I click 'Save') but when I try to create a new page it throws an error that I can't seem to get by. It appears to be firing this at the title entry point and not at the first 'Save/Publish' option once the client has finished editing. Any thoughts?

ProcessPageAdd: Can't save field from a new page - please save the entire page first

function myHook(HookEvent $event) {

	$page = $event->arguments(0);
	if ($page->template->name == 'events-detail') { // What's On detail

		$today = strtotime("now");
		$dateRepeater = $page->events_detail_dates;
		$lastRow = $page->events_detail_dates->last();
		$page->set("events_detail_dates_final_date", $lastRow->events_detail_dates_end_date);
		$page->save("events_detail_dates_final_date");

	}

}
wire()->addHookAfter('Pages::saveReady', null, 'myHook');

 

Posted (edited)

I haven't looked at this in detail. As you await better responses than mine :P, why don't you just do what the error is instructing you to? Save the whole page. If that works, then work on fine tuning so that if new page, save whole page, else, save affected field only. Instead of...

17 minutes ago, oma said:

$page->save("events_detail_dates_final_date");

Save the whole page..

$page->save();

 

Edited by kongondo
Posted
45 minutes ago, Tom. said:

I'm not entirely sure about this, but what about hooking after Pages::save rather than saveReady 

This seemed to have done the trick, Tom! Thanks!

  • Like 1

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...