rash Posted October 31, 2020 Share Posted October 31, 2020 Hi all, when I’m editing a page in the backend, eg. /processwire/page/edit/?id=1032, is there a way to get the currently edited page (here: id=1032) as a page object, let’s call it $pageInEdit? The big plan behind would lead a bit too far, just a simple example what I would like to achieve: if ($pageInEdit->field == 'foo') { // send a message or do something else } Thanks in advance Link to comment Share on other sites More sharing options...
dragan Posted October 31, 2020 Share Posted October 31, 2020 I guess you need to use a hook. Link to comment Share on other sites More sharing options...
rash Posted October 31, 2020 Author Share Posted October 31, 2020 Thanks, @dragan, I guessed exactly the same ? Unfortunately that guess didn’t lead me to somewhere useful yet. When I do $wire->addHookAfter('Page::loaded', function($event) { $page = $event->object; if ($page->whatever) { // do something } }); $page contains all pages, not just the one I’m currently editing. Is there any chance to isolate this particular page in an object? Link to comment Share on other sites More sharing options...
dragan Posted October 31, 2020 Share Posted October 31, 2020 1 hour ago, rash said: The big plan behind would lead a bit too far I don't think so... the trick with PW hooks is to find out which hook to use, and whether to use before or after. Page::loaded seems to be the wrong method to hook into for what you want to achieve. Here are some code-bits I used in the past, and they all work as expected (inside site/ready.php) $this->addHookAfter('Pages::saveReady', function (HookEvent $event) { $page = $event->arguments[0]; // ---------- $pages->addHookAfter("ProcessPageEdit::buildForm", function (HookEvent $event) { $page = $event->object->getPage(); $form = $event->return; // ---------- $this->addHookBefore('Pages::saved(template=invoice, parent=23444)', function(HookEvent $event) { $page = $event->arguments(0); 4 Link to comment Share on other sites More sharing options...
rash Posted October 31, 2020 Author Share Posted October 31, 2020 Another thanks @dragan , Page::loaded was indeed the wrong method. ProcessPageEdit::buildForm delivers the $page object I was looking for – that's great! I have to play around a little with details to find out whether After or Before work better for my needs. Btw: I didn’t want to conceal the big plan, but I first had to check if I get the edit page object done before I could start to concretize a few foggy approaches for getting some rather weird customer wishes done. 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