You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Inability to directly set and save changes to multi-value page reference field via a string of IDs #1900
The asymmetry is in FieldtypePage::sanitizeValuePageArray() (wire/modules/Fieldtype/FieldtypePage/FieldtypePage.module).
When you assign an actual PageArray, it's returned as-is → replaces the existing value.
When you assign a string like '1234|1235', it's first converted by sanitizeValueString(), which returns a PageArray (via getById()). But that converted PageArray then falls into the block that merges each page into the existing value rather than replacing it:
// if it's a new PageArray, combine it with the existing PageArrayif($valueinstanceof PageArray) {
foreach($valueas$pg) {
if(!$pg->id || $pg->id == $page->id) continue;
$pageArray->add($pg); // <-- appends to existing, never clears
}
return$pageArray;
}
$pageArray here is the field's current value, so a string of IDs always appends. That's why setting to null first (or using setAndSave()) is needed as a workaround.
Suggested fix
Treat a string that resolves to a PageArray (multiple values, e.g. "123|456") as an explicit replacement — the same as assigning a real PageArray. Single-value strings ('1234', '-1234' removal marker) keep their existing add/remove behavior, so BC for incremental adds is preserved.
In sanitizeValuePageArray(), change:
// if it's a string, see if we can convert it to a Page or PageArrayif(is_string($value)) $value = $this->sanitizeValueString($page, $field, $value);
to:
// if it's a string, see if we can convert it to a Page or PageArrayif(is_string($value)) {
$value = $this->sanitizeValueString($page, $field, $value);
// a string that resolves to multiple pages (e.g. "123|456") is an explicit// replacement of the whole value rather than an addition to itif($valueinstanceof PageArray) {
foreach($valueas$v) if($v->id == $page->id) $value->remove($v);
return$value;
}
}
This makes $page->field_name = '1234|1235'; $page->save('field_name'); overwrite as expected, while leaving direct-PageArray assignment, single-page adds, and the -id removal syntax untouched.
Activity
adrianbj commentedon Jun 14, 2026
Root cause
The asymmetry is in
FieldtypePage::sanitizeValuePageArray()(wire/modules/Fieldtype/FieldtypePage/FieldtypePage.module).PageArray, it's returned as-is → replaces the existing value.'1234|1235', it's first converted bysanitizeValueString(), which returns aPageArray(viagetById()). But that converted PageArray then falls into the block that merges each page into the existing value rather than replacing it:$pageArrayhere is the field's current value, so a string of IDs always appends. That's why setting tonullfirst (or usingsetAndSave()) is needed as a workaround.Suggested fix
Treat a string that resolves to a
PageArray(multiple values, e.g."123|456") as an explicit replacement — the same as assigning a realPageArray. Single-value strings ('1234','-1234'removal marker) keep their existing add/remove behavior, so BC for incremental adds is preserved.In
sanitizeValuePageArray(), change:to:
This makes
$page->field_name = '1234|1235'; $page->save('field_name');overwrite as expected, while leaving direct-PageArrayassignment, single-page adds, and the-idremoval syntax untouched.matjazpotocnik commentedon Sep 11, 2026
Note: issue #1959 is not related to this issue.