Hurme Posted May 19, 2020 Share Posted May 19, 2020 Hello, Any advice on how to hook page, so its fields get populated by something else than the actual saved content? The below works fine for frontend (it's in ready.php), but has no effect in front-end editing or backend, and that is the problem here. $this->addHookBefore('Page::render', function($event) { $page = $event->object; $page->exampleField = '123'; }); The information doesn't need to be saved into PW itself. It's been fetched and then on save, delivered to another database. Link to comment Share on other sites More sharing options...
kixe Posted May 20, 2020 Share Posted May 20, 2020 // for editing $this->addHookBefore('ProcessPageEdit::execute', function($e) { /* ... */ }); // if page template = user $this->addHookBefore('ProcessProfile::execute', function($e) { /* ... */ }); Link to comment Share on other sites More sharing options...
Hurme Posted June 4, 2020 Author Share Posted June 4, 2020 @kixe I'm probably doing something wrong, but I cannot get your example to do anything. Link to comment Share on other sites More sharing options...
kixe Posted June 4, 2020 Share Posted June 4, 2020 // example 1: modify page title (runtime) for a specific template in Page Edit Interface $this->addHookBefore('ProcessPageEdit::execute', function($e) { $id = wire('input')->get->id; if (!$id) return; $page = wire('pages')->get($id); if ($page->template != 'specific') return; $page->title = "I am a runtime title for pages using template 'specific'"; }); // example 2: modify fields in Profile $this->addHookBefore('ProcessProfile::execute', function($e) { // not for superuser if (wire('user')->isSuperuser()) return; // the user should check 2 checkboxes in its profile // after checking and saving the related checkbox disappears // if both are checked a markup field 'info' is shown $profileFields = $e->object->profileFields; if (wire('user')->checkbox && wire('user')->checkbox_2) $profileFields[] = 'info'; else { if (wire('user')->checkbox != 1) $profileFields[] = 'checkbox'; if (wire('user')->checkbox_2 != 1) $profileFields[] = 'checkbox_2'; } // update profile fields $e->object->profileFields = array_unique($profileFields); }); 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