mirror of
https://github.com/lucaspalomodevelop/core.git
synced 2026-03-13 08:09:41 +00:00
MVC - move explicit cast in BaseModel when calling field->setValue() to offer the posibility to read structures in custom field types.
This is a requirement for https://github.com/opnsense/core/issues/7904 To avoid moving config items around, we need some way to handle <priv/> and <apikeys/> for example. When `setValue()` receives the `SimpleXMLElement`, we can parse the data into a flattened structure on initial read. All current callers either use an implicit string cast or an explicit one, only the BaseField and LinkAddressField types seem to need an explicit one.
This commit is contained in:
parent
c345e01de2
commit
416b6ee144
@ -241,7 +241,7 @@ abstract class BaseModel
|
||||
}
|
||||
if ($config_data != null && isset($config_data->$tagName)) {
|
||||
// set field content from config (if available)
|
||||
$fieldObject->setValue((string)$config_data->$tagName);
|
||||
$fieldObject->setValue($config_data->$tagName);
|
||||
}
|
||||
} else {
|
||||
// add new child node container, always try to pass config data
|
||||
|
||||
@ -365,15 +365,15 @@ abstract class BaseField
|
||||
|
||||
/**
|
||||
* default setter
|
||||
* @param string $value set field value
|
||||
* @param SimpleXMLElement|string $value set field value
|
||||
*/
|
||||
public function setValue($value)
|
||||
{
|
||||
// if first set and not altered by the user, store initial value
|
||||
if ($this->internalFieldLoaded === false && $this->internalInitialValue === false) {
|
||||
$this->internalInitialValue = $value;
|
||||
$this->internalInitialValue = (string)$value;
|
||||
}
|
||||
$this->internalValue = $value;
|
||||
$this->internalValue = (string)$value;
|
||||
// apply filters, may be extended later.
|
||||
$filters = array('applyFilterChangeCase');
|
||||
foreach ($filters as $filter) {
|
||||
|
||||
@ -138,6 +138,7 @@ class LinkAddressField extends BaseField
|
||||
*/
|
||||
public function setValue($value)
|
||||
{
|
||||
$value = (string)$value;
|
||||
$parent = $this->getParentNode();
|
||||
if (Util::isIpAddress($value)) {
|
||||
$parent->ipaddr = $value;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user