Commit 539e6767 authored by Ad Schellevis's avatar Ad Schellevis

(mvc model) apply defaults on new array items

parent 4f728e38
...@@ -103,12 +103,15 @@ class ArrayField extends BaseField ...@@ -103,12 +103,15 @@ class ArrayField extends BaseField
); );
foreach ($new_record as $key => $node) { foreach ($new_record as $key => $node) {
// initialize field with new internal id and defined default value
$node->setInternalReference($container_node->__reference.".".$key); $node->setInternalReference($container_node->__reference.".".$key);
$node->applyDefault();
$container_node->addChildNode($key, $node); $container_node->addChildNode($key, $node);
// make sure we have a UUID on repeating child items
$container_node->setAttributeValue("uuid", $this->generateUUID());
} }
// make sure we have a UUID on repeating child items
$container_node->setAttributeValue("uuid", $this->generateUUID());
// add node to this object // add node to this object
$this->addChildNode(null, $container_node); $this->addChildNode(null, $container_node);
......
...@@ -55,6 +55,11 @@ abstract class BaseField ...@@ -55,6 +55,11 @@ abstract class BaseField
*/ */
protected $internalValue = ""; protected $internalValue = "";
/**
* @var null|string node default value
*/
protected $internalDefaultValue = "";
/** /**
* @var string direct reference to this field in the model object * @var string direct reference to this field in the model object
*/ */
...@@ -426,6 +431,15 @@ abstract class BaseField ...@@ -426,6 +431,15 @@ abstract class BaseField
public function setDefault($value) public function setDefault($value)
{ {
$this->internalValue = $value; $this->internalValue = $value;
$this->internalDefaultValue = $value;
}
/**
* (re)Apply default value
*/
public function applyDefault()
{
$this->internalValue = $this->internalDefaultValue;
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment