processwire-issues
processwire-issues copied to clipboard
RepeaterMatrixPageArray: removeAll() not working if we set field content just after.
Short description of the issue
In this hook, removeAll() is not removing until I comment out last line (set clone). Actually after page saved, repeater contains new items AND previous items. I can't find a way to remove all.
protected static function onSaveReady(HookEvent $event, EveningRacePage $page, mixed $eventObject): void
{
if (!self::getChanges($page)->has('raceSessionsTemplate')) {
return;
}
/** @var RaceSessionsTemplatePage $sessionsTemplate */
$sessionsTemplate = $page->raceSessionsTemplate;
$page->raceSessions->removeAll(); // removeAll() alone works...
// $page->raceSessions = null;
$page->raceSessions = clone $sessionsTemplate->raceSessions; // ... but it doesn't work when this line is there.
}
This is probably the same issue as in this report: https://github.com/processwire/processwire-issues/issues/1959
Expected behavior
Having only new items.
Actual behavior
Having both previous and new items.
Optional: Screenshots/Links that demonstrate the issue
- Field before page save:
- Field I try to import to replace all items:
- Result:
Workaround
$page->raceSessions->removeAll();
foreach ($sessionsTemplate->raceSessions as $raceSession){
$page->raceSessions->add($raceSession);
}
Setup/Environment
- ProcessWire version: 3.0.228