Skip to content

Commit 467bcf9

Browse files
committed
Dnat: Put enabled below disabled in model
1 parent a82cdf0 commit 467bcf9

2 files changed

Lines changed: 6 additions & 14 deletions

File tree

src/opnsense/mvc/app/models/OPNsense/Firewall/DNat.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
<Required>Y</Required>
1212
<!-- Intentionally no default set as its applied by actionPostLoadingEvent() -->
1313
</sequence>
14-
<enabled type=".\DNatEnabledField" volatile="true"/>
1514
<!-- legacy disabled flag for compatibility -->
1615
<disabled type="BooleanField"/>
16+
<enabled type=".\DNatEnabledField" volatile="true"/>
1717
<nordr type="BooleanField"/>
1818
<interface type="InterfaceField">
1919
<Multiple>Y</Multiple>

src/opnsense/mvc/app/models/OPNsense/Firewall/FieldTypes/DNatEnabledField.php

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,25 +38,17 @@ public function setValue($value)
3838
return;
3939
}
4040
$value = (string)$value;
41-
$parent = $this->getParentNode();
4241
// Set disabled value opposite of enabled value for legacy compatibility.
43-
if ($parent !== null && isset($parent->disabled) && $value !== '') {
44-
$parent->disabled = $value === '1' ? '0' : '1';
45-
}
42+
$this->getParentNode()->disabled = $value === '1' ? '0' : '1';
4643
return parent::setValue($value);
4744
}
4845

4946
public function getValue(): string
5047
{
51-
$value = parent::getValue();
52-
$isNotInitialized = $this->internalInitialValue === false;
53-
// Get value from disabled flag if enabled does not have a value set.
54-
if ($isNotInitialized || $value === '') {
55-
$parent = $this->getParentNode();
56-
if ($parent !== null && isset($parent->disabled)) {
57-
return (string)$parent->disabled === '1' ? '0' : '1';
58-
}
48+
$parent = $this->getParentNode();
49+
if ($parent !== null && isset($parent->disabled)) {
50+
return (string)$parent->disabled === '1' ? '0' : '1';
5951
}
60-
return $value;
52+
return parent::getValue();
6153
}
6254
}

0 commit comments

Comments
 (0)