@@ -38,11 +38,27 @@ public function loadSystemPolicy(string $policyKey): ?PolicyLayer {
3838 : $ defaultValue ;
3939
4040 $ layer = (new PolicyLayer ())
41- ->setScope ('system ' )
41+ ->setScope ($ hasExplicitSystemValue ? ' global ' : 'system ' )
4242 ->setValue ($ value )
4343 ->setVisibleToChild (true );
4444
45- if (!$ hasExplicitSystemValue || $ value === $ defaultValue ) {
45+ if (!$ hasExplicitSystemValue ) {
46+ return $ layer ->setAllowChildOverride (true );
47+ }
48+
49+ if ($ value === $ defaultValue ) {
50+ $ allowChildOverride = $ this ->appConfig ->getAppValueString (
51+ $ this ->getSystemAllowOverrideConfigKey ($ definition ->getAppConfigKey ()),
52+ '0 ' ,
53+ ) === '1 ' ;
54+
55+ if ($ allowChildOverride ) {
56+ // Explicitly persisted default value ("let users choose")
57+ return $ layer
58+ ->setAllowChildOverride (true )
59+ ->setAllowedValues ([]);
60+ }
61+
4662 return $ layer ->setAllowChildOverride (true );
4763 }
4864
@@ -167,6 +183,12 @@ public function saveSystemPolicy(string $policyKey, mixed $value, bool $allowChi
167183 $ allowOverrideConfigKey = $ this ->getSystemAllowOverrideConfigKey ($ definition ->getAppConfigKey ());
168184
169185 if ($ normalizedValue === $ defaultValue ) {
186+ if ($ allowChildOverride ) {
187+ $ this ->appConfig ->setAppValueString ($ definition ->getAppConfigKey (), (string )$ normalizedValue );
188+ $ this ->appConfig ->setAppValueString ($ allowOverrideConfigKey , '1 ' );
189+ return ;
190+ }
191+
170192 $ this ->appConfig ->deleteAppValue ($ definition ->getAppConfigKey ());
171193 $ this ->appConfig ->deleteAppValue ($ allowOverrideConfigKey );
172194 return ;
0 commit comments