Adam Kiss Posted January 20, 2013 Share Posted January 20, 2013 Hi, I've been going through API, but I seem to not find what I'm looking for. For one of my websites, I'd like too hook before pages::save() to get all changes on website, and change other, related things based on them. However, I need to act not only upon new value (available via $page->field, $page->get('field'), ...), but I'd need to have access to old value as well. Is this possible somehow? Thank you, Adam Link to comment Share on other sites More sharing options...
Adam Kiss Posted January 20, 2013 Author Share Posted January 20, 2013 I should note, that this is for small website, so I don't mind loading the original page again, into different variable, and comparing it. However, another $pages->get() call gets me the object already in memory. Link to comment Share on other sites More sharing options...
teppo Posted January 20, 2013 Share Posted January 20, 2013 Have you already checked this solution out: http://processwire.com/talk/topic/1067-accessing-previous-version-of-page-beforeafter-page-save/#entry9321? 2 Link to comment Share on other sites More sharing options...
Adam Kiss Posted January 20, 2013 Author Share Posted January 20, 2013 Teppo, thank you. I am an idiot for not searching forums first. 1 Link to comment Share on other sites More sharing options...
netcarver Posted January 20, 2013 Share Posted January 20, 2013 @Adam, did you see the field-change-notifier module? It does pre + post checking on changed fields. 1 Link to comment Share on other sites More sharing options...
Adam Kiss Posted January 20, 2013 Author Share Posted January 20, 2013 Thanks Steve, I've seen it now, but it seems awfully more complicated than what I need. My situation, in reality, is that I've got item1 template, which has page field that links to item2, which is one way connection. I want to hook to beforesave and modify page field in item2 (where applicable), so I may have two way connection between them (and synced). Example: item1 (page id 3000) has one page it links to, page with template item2 (id 4000). If user-admin changes it to item2 id 5000, before the page is saved, I'll go to page 4000 and remove the link, and then go to 5000 and add the link to 3000. and then just let the page save… boom, saved with two way connection Link to comment Share on other sites More sharing options...
Soma Posted January 20, 2013 Share Posted January 20, 2013 I already created a module that does this couple weeks ago. Youll find it on my gist page or in forum. On mobile so toolazy to search it. Link to comment Share on other sites More sharing options...
Soma Posted January 20, 2013 Share Posted January 20, 2013 Ok found it https://gist.github.com/4335296 1 Link to comment Share on other sites More sharing options...
Adam Kiss Posted January 20, 2013 Author Share Posted January 20, 2013 this? https://gist.github.com/4335296 btw, that is awesome, thhanks --- edit: I'm slow asshole. Thanks Soma, I'll check the code, and will be happy, probably --- edit: is this meant to be reusable, or should I adapt it? Link to comment Share on other sites More sharing options...
Soma Posted January 20, 2013 Share Posted January 20, 2013 It is reusable changing the properties in the int. But it was an example for a request of user and team pages. I was working on a little more abstract version but havent continued. It works for small amount of pages but to be more scaleable it would require a different approach. This is just straight forward code and melts your synapses if you look at it for too long. ;-) Link to comment Share on other sites More sharing options...
Adam Kiss Posted January 20, 2013 Author Share Posted January 20, 2013 Yeah, I already see some things I might simplify Anyway, you've probably saved me at least an hour or two, so thank you for that! Link to comment Share on other sites More sharing options...
Adam Kiss Posted January 20, 2013 Author Share Posted January 20, 2013 Hm, okay, I did Soma's way (thus not comparing original/new value, but rather querying for related pages, and changing them on the run). I now react to P::save() and to P::delete(), but what is the event for un-trashing page? P::save()? --- Edit: okay, less asking, more trying. P::save() works for pages that were undeleted, so it's okay. Link to comment Share on other sites More sharing options...
teppo Posted January 20, 2013 Share Posted January 20, 2013 Adam, you should take a look at /wire/core/Pages.php, after that it's pretty obvious where to attach page-related hooks. And for the record, ___restore() and ___restored() are available too if you happen to need them 1 Link to comment Share on other sites More sharing options...
Adam Kiss Posted January 20, 2013 Author Share Posted January 20, 2013 @teppo: I do this, and generally am pretty competent at finding what I want via searching in /core/*; But so it seems that sometimes, probably particularly when I'm thinking about multiple things, I tend forget some obvious solutions (such as searching through forums). Oh well. Thank you though 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