diff --git a/src/Forms/CompositeField.php b/src/Forms/CompositeField.php index e02a3c9df..001f81e1d 100644 --- a/src/Forms/CompositeField.php +++ b/src/Forms/CompositeField.php @@ -379,9 +379,17 @@ class CompositeField extends FormField $this->children->removeByName($fieldName, $dataFieldOnly); } - public function replaceField($fieldName, $newField) + /** + * @param $fieldName + * @param $newField + * @param boolean $dataFieldOnly If this is true, then a field will only + * be replaced if it's a data field. Dataless fields, such as tabs, will + * not be considered for replacement. + * @return bool + */ + public function replaceField($fieldName, $newField, $dataFieldOnly = true) { - return $this->children->replaceField($fieldName, $newField); + return $this->children->replaceField($fieldName, $newField, $dataFieldOnly); } public function rootFieldList() diff --git a/src/Forms/FieldList.php b/src/Forms/FieldList.php index 8bbd04979..027f4d8bc 100644 --- a/src/Forms/FieldList.php +++ b/src/Forms/FieldList.php @@ -379,14 +379,16 @@ class FieldList extends ArrayList * * @param string $fieldName The name of the field to replace * @param FormField $newField The field object to replace with + * @param boolean $dataFieldOnly If this is true, then a field will only be replaced if it's a data field. Dataless + * fields, such as tabs, will be not be considered for replacement. * @return boolean TRUE field was successfully replaced * FALSE field wasn't found, nothing changed */ - public function replaceField($fieldName, $newField) + public function replaceField($fieldName, $newField, $dataFieldOnly = true) { $this->flushFieldsCache(); foreach ($this as $i => $field) { - if ($field->getName() == $fieldName && $field->hasData()) { + if ($field->getName() == $fieldName && (!$dataFieldOnly || $field->hasData())) { $this->items[$i] = $newField; return true; } elseif ($field instanceof CompositeField) {