da² Posted December 13, 2023 Posted December 13, 2023 Hello, I was working on a hook that updates a matrix repeater. I have another hook that should trigger when this repeater is changed, and I found it is not triggered. So I thought that changes are not triggered by API changes (only user changes in admin), so that I should call the second hook myself. But I did another test with "title" field, and found it is triggered by API change. ?♂️ I plan to report the issue on GitHub, but want to ask here before in case I'm missing something. The following code updates the matrix repeater from another repeater, then I update title, then I check if repeater and title changes are tracked, and only title one is: protected static function onSaveReady(HookEvent $event, EveningRacePage $page, mixed $eventObject): void { /** @var RaceSessionsTemplatePage $sessionsTemplate */ $sessionsTemplate = $page->raceSessionsTemplate; $page->raceSessions->removeAll(); foreach ($sessionsTemplate->raceSessions as $raceSession) $page->raceSessions->add($raceSession); $page->title = $page->title . "1"; $changes = $page->getChanges(true); wire()->log->message("title changed" . array_key_exists('title', $changes)); // 1 wire()->log->message("raceSessions changed" . array_key_exists('raceSessions', $changes)); // 0 }
da² Posted December 13, 2023 Author Posted December 13, 2023 I think what is triggering changes detection may be field assignation: $page->myField = $newValue. But then I'm stopped by this bug.
MarkE Posted December 13, 2023 Posted December 13, 2023 22 minutes ago, da² said: then I check if repeater and title changes are tracked, and only title one is: Have you tried $page->save() ?
da² Posted December 13, 2023 Author Posted December 13, 2023 @MarkE This is a saveReady hook, page will be saved at the end.
da² Posted December 13, 2023 Author Posted December 13, 2023 So it seems this is field assignation that triggers change detection, it works like that: $pageSessions = $page->raceSessions; $pageSessions->removeAll(); foreach ($sessionsTemplate->raceSessions as $raceSession) $page->raceSessions->add($raceSession); $page->raceSessions = $pageSessions; // Assignation triggers change detection 1
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