Jump to content

Tracking changes on pages – getting original value


Adam Kiss
 Share

Recommended Posts

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

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

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

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

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 :)

  • Like 1
Link to comment
Share on other sites

@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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...