@@ -1100,12 +1100,20 @@ private function setTypedValue(
11001100 }
11011101
11021102 $ this ->assertParams ($ userId , $ app , $ key );
1103- if (!$ this ->matchAndApplyLexiconDefinition ($ userId , $ app , $ key , $ lazy , $ type , $ flags )) {
1103+ /** @var ?Entry $lexiconEntry */
1104+ $ lexiconEntry = null ;
1105+ if (!$ this ->matchAndApplyLexiconDefinition ($ userId , $ app , $ key , $ lazy , $ type , $ flags , lexiconEntry: $ lexiconEntry )) {
11041106 // returns false as database is not updated
11051107 return false ;
11061108 }
11071109 $ this ->loadConfig ($ userId , $ lazy );
11081110
1111+ // lexicon entry might have requested a check on the value
1112+ $ confirmationClosure = $ lexiconEntry ?->onSetConfirmation();
1113+ if ($ confirmationClosure !== null && !$ confirmationClosure ($ value )) {
1114+ return false ;
1115+ }
1116+
11091117 $ inserted = $ refreshCache = false ;
11101118 $ origValue = $ value ;
11111119 $ sensitive = $ this ->isFlagged (self ::FLAG_SENSITIVE , $ flags );
@@ -1937,6 +1945,7 @@ private function matchAndApplyLexiconDefinition(
19371945 ValueType &$ type = ValueType::MIXED ,
19381946 int &$ flags = 0 ,
19391947 ?string &$ default = null ,
1948+ ?Entry &$ lexiconEntry = null ,
19401949 ): bool {
19411950 $ configDetails = $ this ->getConfigDetailsFromLexicon ($ app );
19421951 if (array_key_exists ($ key , $ configDetails ['aliases ' ]) && !$ this ->ignoreLexiconAliases ) {
@@ -1953,18 +1962,18 @@ private function matchAndApplyLexiconDefinition(
19531962 return true ;
19541963 }
19551964
1956- /** @var Entry $configValue */
1957- $ configValue = $ configDetails ['entries ' ][$ key ];
1965+ /** @var Entry $lexiconEntry */
1966+ $ lexiconEntry = $ configDetails ['entries ' ][$ key ];
19581967 if ($ type === ValueType::MIXED ) {
19591968 // we overwrite if value was requested as mixed
1960- $ type = $ configValue ->getValueType ();
1961- } elseif ($ configValue ->getValueType () !== $ type ) {
1969+ $ type = $ lexiconEntry ->getValueType ();
1970+ } elseif ($ lexiconEntry ->getValueType () !== $ type ) {
19621971 throw new TypeConflictException ('The user config key ' . $ app . '/ ' . $ key . ' is typed incorrectly in relation to the config lexicon ' );
19631972 }
19641973
1965- $ lazy = $ configValue ->isLazy ();
1966- $ flags = $ configValue ->getFlags ();
1967- if ($ configValue ->isDeprecated ()) {
1974+ $ lazy = $ lexiconEntry ->isLazy ();
1975+ $ flags = $ lexiconEntry ->getFlags ();
1976+ if ($ lexiconEntry ->isDeprecated ()) {
19681977 $ this ->logger ->notice ('User config key ' . $ app . '/ ' . $ key . ' is set as deprecated. ' );
19691978 }
19701979
@@ -1976,7 +1985,7 @@ private function matchAndApplyLexiconDefinition(
19761985
19771986 // only look for default if needed, default from Lexicon got priority if not overwritten by admin
19781987 if ($ default !== null ) {
1979- $ default = $ this ->getSystemDefault ($ app , $ configValue ) ?? $ configValue ->getDefault ($ this ->presetManager ->getLexiconPreset ()) ?? $ default ;
1988+ $ default = $ this ->getSystemDefault ($ app , $ lexiconEntry ) ?? $ lexiconEntry ->getDefault ($ this ->presetManager ->getLexiconPreset ()) ?? $ default ;
19801989 }
19811990
19821991 // returning false will make get() returning $default and set() not changing value in database
0 commit comments