mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-31 01:34:09 +02:00
Navigation: Only fail if there's really no chance to create the requested hierarchy
refs #5600
This commit is contained in:
parent
7b5d414c7f
commit
d4a9198310
@ -470,7 +470,7 @@ class Navigation implements ArrayAccess, Countable, IteratorAggregate
|
|||||||
throw new InvalidArgumentException('Argument $config must be an array or a instance of Traversable');
|
throw new InvalidArgumentException('Argument $config must be an array or a instance of Traversable');
|
||||||
}
|
}
|
||||||
|
|
||||||
$flattened = $topLevel = array();
|
$flattened = $orphans = $topLevel = array();
|
||||||
foreach ($config as $sectionName => $sectionConfig) {
|
foreach ($config as $sectionName => $sectionConfig) {
|
||||||
$parentName = $sectionConfig->parent;
|
$parentName = $sectionConfig->parent;
|
||||||
unset($sectionConfig->parent);
|
unset($sectionConfig->parent);
|
||||||
@ -482,16 +482,39 @@ class Navigation implements ArrayAccess, Countable, IteratorAggregate
|
|||||||
$flattened[$parentName]['children'][$sectionName] = $sectionConfig->toArray();
|
$flattened[$parentName]['children'][$sectionName] = $sectionConfig->toArray();
|
||||||
$flattened[$sectionName] = & $flattened[$parentName]['children'][$sectionName];
|
$flattened[$sectionName] = & $flattened[$parentName]['children'][$sectionName];
|
||||||
} else {
|
} else {
|
||||||
|
$orphans[$parentName][$sectionName] = $sectionConfig->toArray();
|
||||||
|
$flattened[$sectionName] = & $orphans[$parentName][$sectionName];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
do {
|
||||||
|
$match = false;
|
||||||
|
foreach ($orphans as $parentName => $children) {
|
||||||
|
if (isset($flattened[$parentName])) {
|
||||||
|
if (isset($flattened[$parentName]['children'])) {
|
||||||
|
$flattened[$parentName]['children'] = array_merge(
|
||||||
|
$flattened[$parentName]['children'],
|
||||||
|
$children
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
$flattened[$parentName]['children'] = $children;
|
||||||
|
}
|
||||||
|
|
||||||
|
unset($orphans[$parentName]);
|
||||||
|
$match = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} while ($match && !empty($orphans));
|
||||||
|
|
||||||
|
if (! empty($orphans)) {
|
||||||
throw new ConfigurationError(
|
throw new ConfigurationError(
|
||||||
t(
|
t(
|
||||||
'Failed to add navigation item "%s". Parent "%s" not found. Make'
|
'Failed to fully parse navigation configuration. Ensure that'
|
||||||
. ' sure that the parent is defined prior to its child(s).'
|
. ' all referenced parents are existing navigation items: %s'
|
||||||
),
|
),
|
||||||
$sectionName,
|
join(', ', array_keys($orphans))
|
||||||
$parentName
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return static::fromArray($topLevel);
|
return static::fromArray($topLevel);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user