gebeer

Repeater isChanged not working when adding image

5 posts in this topic

Hello,

I have a repeater field with an image (single) field. I would like to attach a hook when the repeater item has changed. But the change event is not triggered, when uploading an image. When removing an image the repeater item shows as changed.

Here's my hook

$this->addHookAfter('Pages::saveReady', function(HookEvent $event) {
  $page = $event->arguments[0];
  if($page->template != 'member') return;
    $historyItems = $page->get('history'); // repeater field
    foreach ($historyItems as $key => $item) {
      if($item->isChanged()) bardump('CHANGED');
    }
});

This looks like a bug to me. Can anybody reproduce this? PW 3.0.61

Share this post


Link to post
Share on other sites

You could try hooking after saveReady for the repeater pages themselves:

$this->addHookAfter('Pages::saveReady', function(HookEvent $event) {
    $page = $event->arguments[0];
    if($page->template != 'repeater_history') return;
    if($page->isChanged()) bardump('CHANGED');
});

 

Share this post


Link to post
Share on other sites

@Robin S That is pretty neat! And I will use it to execute my logic.

For testing, I am using this now:

$this->addHookAfter('Pages::saveReady', function(HookEvent $event) {
  $page = $event->arguments[0];
  if($page->template == 'repeater_history') bardump($page->isChanged()); // this line is not executed when adding an image and then saving the page
});

BUT it still doesn't trigger page change when I upload an image to the repeater item and then save the page. Deleting the image does trigger page as changed. So same behavior as with my above hook code.

Looks like a bug to me. On a normal page (non repeater) the change event is triggered when uploading an image and then saving the page. Only for  repeater pages this does not happen.

Share this post


Link to post
Share on other sites
7 minutes ago, gebeer said:

BUT it still doesn't trigger page change when I upload an image to the repeater item and then save the page.

Hmm, I just tested this and it works for me. That is, $page->isChanged() returns true after uploading an image to a repeater item and saving the containing page. And I checked on an existing repeater item as isChanged() is always true for new pages. So weird that it isn't working for you.

Share this post


Link to post
Share on other sites

@Robin S thanks for checking. I have quite a few other hooks going on that might interfere. I thought I had checked on them already. But will do another thorough check and get back here.

Share this post


Link to post
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

  • Recently Browsing   0 members

    No registered users viewing this page.