zyON Posted May 29, 2014 Share Posted May 29, 2014 I need to get the name of a page at the moment when it is permanently removed from the Trash. I need this because I have to do some cleanup for files associated with it that I'm uploading to Amazon S3 with a module I'm trying to develop. Now, for example, it I use the following hook: $this->addHook('Pagefiles::delete', $this, 'deleteStuff'); I can get the name of the file being deleted, the field it belongs to but when I try to get the page name I get a different name like this: "pageid_pagename" not the original page name. public function deleteStuff($event){ $file = $event->arguments(0); $filename = $file->name; // filename OK $field = $file->field->name; // field name OK $page = $file->page->name // Not what I was looking for (...) The page name is changed when the page is moved to the Trash. Any ideas on how can I get the clean name (without parsing this new string)? Link to comment Share on other sites More sharing options...
teppo Posted May 29, 2014 Share Posted May 29, 2014 @zyON: at that point the original name, one without "pageid_" prefix, is nowhere to be found. Hence you actually need to strip the prefix to get the original name. Take a look at how ProcessWire itself does this when restoring pages from trash: https://github.com/ryancramerdesign/ProcessWire/blob/master/wire/core/Pages.php#L1006. 3 Link to comment Share on other sites More sharing options...
zyON Posted June 2, 2014 Author Share Posted June 2, 2014 Teppo, Ok, thanks. That's what I'm doing now. Link to comment Share on other sites More sharing options...
Soma Posted June 2, 2014 Share Posted June 2, 2014 You would use a after Page::deleteReady hook to fetch the page that's going to be deleted. This hook is called when page is deletable and actually WILL get deleted right after. $this->addHook("Class:method", $this, "someMethod"); is to add a new method to a class with a hook. You would give it addHookAfter or addHookBefore. 2 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