Commit 4b16c753 authored by Ad Schellevis's avatar Ad Schellevis

add post loading event to BaseField

parent 968a31b3
......@@ -54,7 +54,7 @@ class PageController extends ControllerBase
$node_found = $mdlSample->setNodeByReference(implode(".", $refparts), $value);
// new node in the post which is not on disc, create a new child node
// we need to create new nodes in memory for Array types
if ($node_found == null && strpos($key, 'childnodes_section_') !== false) {
if ($node_found == false && strpos($key, 'childnodes_section_') !== false) {
// because all the array items are numbered in order, we know that any item not found
// must be a new one.
$mdlSample->childnodes->section->add();
......@@ -140,17 +140,12 @@ class PageController extends ControllerBase
$cnf = Config::getInstance();
$cnf->save();
}
}
// redirect to index
$this->dispatcher->forward(array(
"action" => "index"
));
// redirect to index
$this->dispatcher->forward(array(
"action" => "index"
));
} else {
// Forward flow to the index action
$this->dispatcher->forward(array(
"action" => "index"
));
}
}
}
......@@ -192,7 +192,8 @@ abstract class BaseModel
// We've loaded the model template, now let's parse it into this object
$this->parseXml($model_xml->items, $config_array, $this->internalData) ;
//print_r($this->internalData);
// trigger post loading event
$this->internalData->eventPostLoading();
// call Model initializer
$this->init();
......
......@@ -56,9 +56,10 @@ class ArrayField extends BaseField
}
/**
* copy first node pointer as template node to make sure we always have a template to create new nodes from.
* Copy first node pointer as template node to make sure we always have a template to create new nodes from.
* If the first node is virtual (no source data), remove that from the list.
*/
private function internalCopyStructure()
protected function actionPostLoadingEvent()
{
// always make sure there's a node to copy our structure from
if ($this->internalTemplateNode ==null) {
......@@ -80,8 +81,6 @@ class ArrayField extends BaseField
*/
public function add()
{
$this->internalCopyStructure();
$new_record = array();
foreach ($this->internalTemplateNode->__items as $key => $node) {
if ($node->isContainer()) {
......@@ -113,7 +112,6 @@ class ArrayField extends BaseField
*/
public function del($index)
{
$this->internalCopyStructure();
if (array_key_exists((string)$index, $this->internalChildnodes)) {
unset($this->internalChildnodes[$index]);
}
......
......@@ -80,6 +80,25 @@ abstract class BaseField
*/
protected $internalIsVirtual = false ;
/**
* Template action for post loading actions, triggered by eventPostLoadingEvent.
* Overwrite this method for custom loading hooks.
*/
protected function actionPostLoadingEvent()
{
return;
}
/**
* trigger post loading event. (executed by BaseModel)
*/
public function eventPostLoading()
{
foreach ($this->internalChildnodes as $nodeName => $node) {
$node->eventPostLoading();
}
$this->actionPostLoadingEvent();
}
/**
* @return bool returns if this a container type object (no data)
......@@ -242,7 +261,7 @@ abstract class BaseField
}
/**
* Recursive method to flatten tree structure for easy validation.
* Recursive method to flatten tree structure for easy validation, returns only leaf nodes.
* @return array named array with field type nodes, using the internal reference.
*/
public function getFlatNodes()
......@@ -326,4 +345,5 @@ abstract class BaseField
$parts = explode("\\", get_class($this));
return $parts[count($parts)-1];
}
}
......@@ -12,10 +12,10 @@
and the actual data from the Sample model, which is a combination of the data presented in the config.xml and the defaults set in the model xml.
<br/><br/>
When errors occur while saving this form, they will be shown below:
When errors occur while saving this form, they will be shown below: <br/>
{% for error_message in error_messages %}
<i style="color:red"> {{ error_message['field'] }} : {{ error_message['msg'] }} </i> <br>
<i style="color:red"> {{ error_message['field'] }} : {{ error_message['msg'] }} </i> <br/>
{% endfor %}
<br/><br/>
......
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