NavigationConfigForm: Do not allow to configure circular parent child relations

refs #5600
This commit is contained in:
Johannes Meyer 2015-09-17 15:53:12 +02:00
parent 6e2d7dca9b
commit 996224f54a
1 changed files with 33 additions and 2 deletions

View File

@ -194,6 +194,8 @@ class NavigationConfigForm extends ConfigForm
}
}
$children = $this->itemToLoad ? $this->getFlattenedChildren($this->itemToLoad) : array();
$names = array();
if ($shared) {
foreach ($this->getShareConfig() as $sectionName => $sectionConfig) {
@ -201,22 +203,51 @@ class NavigationConfigForm extends ConfigForm
$sectionName !== $this->itemToLoad
&& $sectionConfig->type === $type
&& $sectionConfig->owner === $this->getUser()->getUsername()
&& !in_array($sectionName, $children, true)
) {
$names[] = $sectionName;
}
}
} else {
foreach ($this->getUserConfig() as $sectionName => $sectionConfig) {
if ($sectionName !== $this->itemToLoad && $sectionConfig->type === $type) {
if (
$sectionName !== $this->itemToLoad
&& $sectionConfig->type === $type
&& !in_array($sectionName, $children, true)
) {
$names[] = $sectionName;
}
}
}
// TODO: Ensure that it's not possible to produce circular references
return $names;
}
/**
* Recursively return all children of the given navigation item
*
* @param string $name
*
* @return array
*/
protected function getFlattenedChildren($name)
{
$config = $this->getConfigForItem($name);
if ($config === null) {
return array();
}
$children = array();
foreach ($config as $sectionName => $sectionConfig) {
if ($sectionConfig->parent === $name) {
$children[] = $sectionName;
$children = array_merge($children, $this->getFlattenedChildren($sectionName));
}
}
return $children;
}
/**
* Populate the form with the given navigation item's config
*