Jump to content

Recommended Posts

Posted

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

Posted

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.

Posted

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

Posted

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.

Posted

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. ;-)

Posted

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

Posted

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
Posted

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

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
  • Recently Browsing   0 members

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