@@ -20,31 +20,11 @@ class CustomVarEnricher extends CustomVarEnricherHook
2020{
2121 protected $ fieldConfig ;
2222
23- protected $ datalistMaps ;
23+ protected $ datalistMaps = [] ;
2424
2525 protected $ groups = [];
2626
27- public function prefetchForObject (Model $ object ): bool
28- {
29- return false ;
30- }
31-
32- public function renderCustomVarKey (string $ key )
33- {
34- return $ key ;
35- }
36-
37- public function renderCustomVarValue (string $ key , $ value )
38- {
39- return $ value ;
40- }
41-
42- public function identifyCustomVarGroup (string $ key ): ?string
43- {
44- return null ;
45- }
46-
47- public function enrichCustomVars (array $ vars , Model $ object ): array
27+ public function enrichCustomVars (array &$ vars , Model $ object ): array
4828 {
4929 $ directorObject = null ;
5030 $ connection = Db::fromResourceName (Config::module ('director ' )->get ('db ' , 'resource ' ));
@@ -62,12 +42,21 @@ public function enrichCustomVars(array $vars, Model $object): array
6242 $ this ->fieldConfig = (new IcingaObjectFieldLoader ($ directorObject ))->getFields ();
6343
6444 $ this ->buildDataListMap ($ connection );
45+
6546 if ($ directorObject ) {
66- foreach ($ vars as $ varName => $ customVar ) {
67- $ newVars [$ varName ] = $ this ->resolveCustomVarMapping ($ varName , $ customVar , $ connection );
47+ $ varsToReplace = json_decode (json_encode ($ directorObject ->getVars ()), true )
48+ + json_decode (json_encode ($ directorObject ->getInheritedVars ()), true );
49+
50+
51+ foreach ($ varsToReplace as $ varName => $ customVar ) {
52+ if (isset ($ vars [$ varName ])) {
53+ $ newVars [] = $ this ->resolveCustomVarMapping ($ varName , $ customVar , $ connection );
54+
55+ unset($ vars [$ varName ]);
56+ }
6857 }
69- } else {
70- $ newVars = $ vars ;
58+
59+ $ newVars = array_merge ([], ... $ newVars ) ;
7160 }
7261
7362 return $ newVars ;
@@ -128,6 +117,8 @@ protected function resolveCustomVarMapping(string $name, $val, DbConnection $con
128117 } else {
129118 $ this ->groups [$ field ->getCategoryName ()][$ name ] = $ val ;
130119 }
120+
121+ return [];
131122 }
132123 } elseif (is_array ($ val )) {
133124 $ newValue = [];
0 commit comments