Skip to content

RepeaterMatrixPageArray: removeAll() not working if we set field content just after. #1860

@hiboudev

Description

@hiboudev

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: #1959

Expected behavior

Having only new items.

Actual behavior

Having both previous and new items.

Optional: Screenshots/Links that demonstrate the issue

  1. Field before page save:
    image
  2. Field I try to import to replace all items:
    image
  3. Result:
    image

Workaround

$page->raceSessions->removeAll();

foreach ($sessionsTemplate->raceSessions as $raceSession){
    $page->raceSessions->add($raceSession);
}

Setup/Environment

  • ProcessWire version: 3.0.228

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions