88use Exception ;
99use Icinga \Application \Config ;
1010use Icinga \Web \Widget \ShowConfiguration ;
11+ use ipl \Html \FormElement \PasswordElement ;
1112use ipl \Stdlib \Str ;
1213use ipl \Web \Common \CsrfCounterMeasure ;
1314use ipl \Web \Compat \CompatForm ;
@@ -95,6 +96,23 @@ protected function getConfigValue(string $name, mixed $default = null): mixed
9596 return $ this ->config ->get ($ section , $ key , $ default );
9697 }
9798
99+ /**
100+ * Checks if the element should be reverted to the value from the INI file if empty.
101+ * This is useful for elements that aren't populated from the INI file.
102+ *
103+ * @param string $elementName The name of the element to check
104+ *
105+ * @return bool
106+ */
107+ protected function shouldRevertIfEmpty (string $ elementName ): bool
108+ {
109+ $ element = $ this ->getElement ($ elementName );
110+ return match (true ) {
111+ $ element instanceof PasswordElement => true ,
112+ default => false ,
113+ };
114+ }
115+
98116 /**
99117 * Persist the current configuration to disk
100118 *
@@ -108,7 +126,9 @@ protected function save(): void
108126 continue ;
109127 }
110128 [$ section , $ key ] = $ parts ;
111-
129+ if (Str::isEmpty ($ value ) && $ this ->shouldRevertIfEmpty ($ element )) {
130+ $ value = $ this ->config ->get ($ section , $ key );
131+ }
112132 $ configSection = $ this ->config ->getSection ($ section );
113133 if (Str::isEmpty ($ value )) {
114134 unset($ configSection [$ key ]);
0 commit comments