From 50d28a0ad8dcf5d9fe697278b6ea05aa00f8fb87 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Tue, 5 Nov 2019 18:01:37 +0100 Subject: [baseconfig] Overhaul hook system This enables us to finally properly show the inheritance flow of all the config variables when editing the baseconfig for a certain location or machine. --- .../locations/inc/locationhooks.inc.php | 28 ++++++++++------------ 1 file changed, 13 insertions(+), 15 deletions(-) (limited to 'modules-available/locations/inc/locationhooks.inc.php') diff --git a/modules-available/locations/inc/locationhooks.inc.php b/modules-available/locations/inc/locationhooks.inc.php index c15c34ab..5ce3bbfe 100644 --- a/modules-available/locations/inc/locationhooks.inc.php +++ b/modules-available/locations/inc/locationhooks.inc.php @@ -4,28 +4,26 @@ class LocationHooks { /** - * Used for baseconfig hook - * @param $locationId - * @return bool|array ('value' => x, 'display' => y), false if no parent or unknown id + * Resolve baseconfig id to locationid -- noop in this case */ - public static function getBaseconfigParent($locationId) + public static function baseconfigLocationResolver($id) { - $locationId = (int)$locationId; - $assoc = Location::getLocationsAssoc(); - if (!isset($assoc[$locationId])) - return false; - $locationId = (int)$assoc[$locationId]['parentlocationid']; - if (!isset($assoc[$locationId])) - return false; - return array('value' => $locationId, 'display' => $assoc[$locationId]['locationname']); + return $id; } /** - * Resolve baseconfig id to locationid -- noop in this case + * Hook to get inheritance tree for all config vars + * @param int $id Locationid currently being edited */ - public static function baseconfigLocationResolver($id) + public static function baseconfigInheritance($id) { - return $id; + $locs = Location::getLocationsAssoc(); + if ($locs === false || !isset($locs[$id])) + return []; + BaseConfig::prepareWithOverrides([ + 'locationid' => $locs[$id]['parentlocationid'] + ]); + return ConfigHolder::getRecursiveConfig(true); } } \ No newline at end of file -- cgit v1.2.3-55-g7522