mirror of
https://github.com/lucaspalomodevelop/core.git
synced 2026-03-18 02:25:05 +00:00
mvc - extend model implementation to support volatile fields, these fields will be validated when offered, but will not be serialized to the target xml structure.
Example usage: <serial type="IntegerField" volatile="true"/> The advantage of this is one can ask the user for input, validate it when offered and report back when it's not valid.
This commit is contained in:
parent
8973f6efb1
commit
c868e0adc6
@ -215,6 +215,9 @@ abstract class BaseModel
|
||||
}
|
||||
$fieldObject = $field_rfcls->newInstance($new_ref, $tagName);
|
||||
$fieldObject->setParentModel($this);
|
||||
if (($xmlNode->attributes()["volatile"] ?? '') == 'true') {
|
||||
$fieldObject->setInternalIsVolatile();
|
||||
}
|
||||
|
||||
// now add content to this model (recursive)
|
||||
if ($fieldObject->isContainer() == false) {
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright (C) 2015-2020 Deciso B.V.
|
||||
* Copyright (C) 2015-2024 Deciso B.V.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@ -105,6 +105,11 @@ abstract class BaseField
|
||||
*/
|
||||
protected $internalIsVirtual = false;
|
||||
|
||||
/**
|
||||
* @var bool node (and subnodes) is volatile (non persistent, but should validate when offered)
|
||||
*/
|
||||
protected $internalIsVolatile = false;
|
||||
|
||||
/**
|
||||
* @var array key value store for attributes (will be saved as xml attributes)
|
||||
*/
|
||||
@ -573,6 +578,23 @@ abstract class BaseField
|
||||
return $this->internalIsVirtual;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark this node as volatile
|
||||
*/
|
||||
public function setInternalIsVolatile()
|
||||
{
|
||||
$this->internalIsVolatile = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns if this node is volatile, the framework uses this to determine if this node should be stored.
|
||||
* @return bool is volatile node
|
||||
*/
|
||||
public function getInternalIsVolatile()
|
||||
{
|
||||
return $this->internalIsVolatile;
|
||||
}
|
||||
|
||||
/**
|
||||
* getter for internal tag name
|
||||
* @return null|string xml tagname to use
|
||||
@ -687,8 +709,8 @@ abstract class BaseField
|
||||
}
|
||||
|
||||
foreach ($this->iterateItems() as $key => $FieldNode) {
|
||||
if ($FieldNode->getInternalIsVirtual()) {
|
||||
// Virtual fields should never be persisted
|
||||
if ($FieldNode->getInternalIsVirtual() || $FieldNode->getInternalIsVolatile()) {
|
||||
// Virtual and volatile fields should never be persisted
|
||||
continue;
|
||||
}
|
||||
$FieldNode->addToXMLNode($subnode);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user