diff --git a/src/opnsense/mvc/app/models/OPNsense/Base/BaseModel.php b/src/opnsense/mvc/app/models/OPNsense/Base/BaseModel.php index 529b16f02..c9d9d3a78 100644 --- a/src/opnsense/mvc/app/models/OPNsense/Base/BaseModel.php +++ b/src/opnsense/mvc/app/models/OPNsense/Base/BaseModel.php @@ -232,7 +232,9 @@ abstract class BaseModel } // iterate array items from config data - $child_node = new ContainerField($fieldObject->__reference . "." . $tagUUID, $tagName); + $child_node = $fieldObject->newContainerField( + $fieldObject->__reference . "." . $tagUUID, $tagName + ); $this->parseXml($xmlNode, $conf_section, $child_node); if (!isset($conf_section->attributes()->uuid)) { // if the node misses a uuid, copy it to this nodes attributes @@ -243,7 +245,9 @@ abstract class BaseModel } else { // There's no content in config.xml for this array node. $tagUUID = $internal_data->generateUUID(); - $child_node = new ContainerField($fieldObject->__reference . "." . $tagUUID, $tagName); + $child_node = $fieldObject->newContainerField( + $fieldObject->__reference . "." . $tagUUID, $tagName + ); $child_node->setInternalIsVirtual(); $this->parseXml($xmlNode, $config_section_data, $child_node); $fieldObject->addChildNode($tagUUID, $child_node); @@ -270,7 +274,7 @@ abstract class BaseModel $internalConfigHandle = Config::getInstance(); // init new root node, all details are linked to this - $this->internalData = new FieldTypes\ContainerField(); + $this->internalData = new ContainerField(); // determine our caller's filename and try to find the model definition xml // throw error on failure diff --git a/src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/ArrayField.php b/src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/ArrayField.php index 51a4b776f..4dcd5cc6b 100644 --- a/src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/ArrayField.php +++ b/src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/ArrayField.php @@ -60,6 +60,20 @@ class ArrayField extends BaseField } } + /** + * Construct new content container and attach to this items model + * @param $ref + * @param $tagname + * @return ContainerField + */ + public function newContainerField($ref, $tagname) + { + $container_node = new ContainerField($ref, $tagname); + $parentmodel = $this->getParentModel(); + $container_node->setParentModel($parentmodel); + return $container_node; + } + /** * retrieve read only template with defaults (copy of internal structure) * @return null|BaseField template node @@ -87,13 +101,7 @@ class ArrayField extends BaseField } $nodeUUID = $this->generateUUID(); - $container_node = new ContainerField( - $this->__reference . "." . $nodeUUID, - $this->internalXMLTagName - ); - $parentmodel = $this->getParentModel(); - $container_node->setParentModel($parentmodel); - + $container_node = $this->newContainerField($this->__reference . "." . $nodeUUID, $this->internalXMLTagName); foreach ($new_record as $key => $node) { // initialize field with new internal id and defined default value $node->setInternalReference($container_node->__reference . "." . $key);