BillH Posted November 4, 2019 Share Posted November 4, 2019 It feels like this should be obvious or it should be easy to find a solution in the forums, but I've got stuck! I'm trying to set the value of a field (based on other field values) when an existing page loads for editing. Here's a reduced test version of the code that doesn't work, from ready.php: wire()->addHookAfter('Page::loaded', function($event) { $page = $event->object; if ($page->template == 'article') { // Get field values and do calculations here // but for testing: $calculatedValue = "Testing 123"; $page->of(false); $page->set('test_field', $calculatedValue); } }); Note that if I start the code like this, it works fine when the page is saved: wire()->addHookAfter('Pages::saveReady', function($event) { $page = $event->arguments[0]; if ($page->template... So I presume there's something wrong with the hook or getting the page. But what? Link to comment Share on other sites More sharing options...
wbmnfktr Posted November 8, 2019 Share Posted November 8, 2019 Maybe it's enough to hook into it before the page is ready to be saved. wire()->addHookBefore('Pages::saveReady', function($event) { 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