a-ok Posted December 11, 2017 Share Posted December 11, 2017 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'); Link to comment Share on other sites More sharing options...
Tom. Posted December 11, 2017 Share Posted December 11, 2017 I'm not entirely sure about this, but what about hooking after Pages::save rather than saveReady 2 Link to comment Share on other sites More sharing options...
kongondo Posted December 11, 2017 Share Posted December 11, 2017 (edited) I haven't looked at this in detail. As you await better responses than mine , 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 December 11, 2017 by kongondo Link to comment Share on other sites More sharing options...
a-ok Posted December 11, 2017 Author Share Posted December 11, 2017 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! 1 Link to comment Share on other sites More sharing options...
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