From 6882abe40abd19f25c5417993c2020119bef86d1 Mon Sep 17 00:00:00 2001 From: Ryan Cramer Date: Mon, 6 Aug 2018 08:21:21 -0400 Subject: [PATCH] Fix issue processwire/processwire-issues#653 Inputfield parent issue causing out of memory errors when two buttons lacking name attributes --- wire/core/Inputfield.php | 21 ++++++++++++++++++++- wire/core/InputfieldWrapper.php | 1 + 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/wire/core/Inputfield.php b/wire/core/Inputfield.php index 4b31fe99..7b2ef4bd 100644 --- a/wire/core/Inputfield.php +++ b/wire/core/Inputfield.php @@ -493,12 +493,31 @@ abstract class Inputfield extends WireData implements Module { */ public function setParent(InputfieldWrapper $parent) { if($this->parent && $this->parent instanceof InputfieldWrapper && $this->parent !== $parent) { - $this->parent->remove($this); + $oldRootParent = $this->getRootParent(); + if(!$oldRootParent) $oldRootParent = $this->parent; + $newRootParent = $parent->getRootParent(); + if(!$newRootParent) $newRootParent = $parent; + if($oldRootParent === $newRootParent) { + // if field staying in the same form, remove from previous parent + $this->parent->remove($this); + } } $this->parent = $parent; return $this; } + /** + * Unset any previously set parent + * + * #pw-internal + * @return $this + * + */ + public function unsetParent() { + $this->parent = null; + return $this; + } + /** * Get this Inputfield’s parent InputfieldWrapper, or NULL if it doesn’t have one. * diff --git a/wire/core/InputfieldWrapper.php b/wire/core/InputfieldWrapper.php index dc68e000..0b4f0fb9 100644 --- a/wire/core/InputfieldWrapper.php +++ b/wire/core/InputfieldWrapper.php @@ -416,6 +416,7 @@ class InputfieldWrapper extends Inputfield implements \Countable, \IteratorAggre array_push($wrappers, $inputfield); } + $inputfield->unsetParent(); $wrapper->add($inputfield); }