Jump to content

Radon

Members
  • Posts

    4
  • Joined

  • Last visited

Recent Profile Visitors

40 profile views

Radon's Achievements

Newbie

Newbie (2/6)

0

Reputation

  1. I discovered that new items in $oldPage have the status 3073 (what matches Page::statusHidden, Page::statusUnpublished). So my way to detect new pages to check if($item->isHidden() && $item->isUnpublished()) $newItem = true;
  2. Intern it seems that getFresh() works similar like my example above, in my tests both methods work exacly identical. I would prefer getFresh(), because it looks more understandable in code. But I still discovered one issue with both methods... When I remove an item from my field, it works like expected, and the "oldPage" still contains the the removed item, while the current page doesn`t contain it. But in the oposide way, when I add a new Item, BOTH variables oldPage AND current page already contain the new item (no matter if I use getFresh() or the code from my post). I think the reason is, because the field is a repeater and repeater items are created as separate page. Maybe the creation of the Repeater Item comes even before my hook, and already adds the item to the page. Any ideas how to fix this ?
  3. Finally after a half day if searching an testing I think I have found a solution that works in how-to-get-a-list-of-all-changes-on-page-save#comment-203833 if anyone needs this, use this code: $oldPage = $this->pages->getById($page->id, array( 'cache' => false, // don't let it write to cache 'getFromCache' => false,// don't let it read from cache 'getOne' => true, // return a Page instead of a PageArray )); it gives the unsaved page and works in the current master version.
  4. I have the same request like Pete and the autor of Hooks, compare page before and after save , I need the unchanged page in the state like it was before the page was saved. Before reading this post, I tried to implement a hook before Pages::save, but I always get the changed page there. I tried to add your code to get the old page, but 1. it still gives me the already changed page, and 2. adding this code reverts the changes after saving. I mean, I change something in the page, save this page, (my hook is triggered), when the saved page in backend is reloaded, my changes are gone. That is my code: $this->addHookBefore('Pages::save', function (HookEvent $event) { $page = $event->arguments(0); if ($page->hasField('my_questions')) { wire('pages')->uncacheAll(); $oldPage = wire('pages')->get($page->id); $this->log("Questions before: " . $page->my_questions); $this->log("Questions after : " . $oldPage->my_questions); } }); Any ideas how I can get the "oldPage" that realy works? p.s. I am working in ProcessWire 3.0.184
×
×
  • Create New...