NavigationConfigForm: Do not allow to configure circular parent child relations
refs #5600
This commit is contained in:
parent
6e2d7dca9b
commit
996224f54a
|
@ -194,6 +194,8 @@ class NavigationConfigForm extends ConfigForm
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$children = $this->itemToLoad ? $this->getFlattenedChildren($this->itemToLoad) : array();
|
||||||
|
|
||||||
$names = array();
|
$names = array();
|
||||||
if ($shared) {
|
if ($shared) {
|
||||||
foreach ($this->getShareConfig() as $sectionName => $sectionConfig) {
|
foreach ($this->getShareConfig() as $sectionName => $sectionConfig) {
|
||||||
|
@ -201,22 +203,51 @@ class NavigationConfigForm extends ConfigForm
|
||||||
$sectionName !== $this->itemToLoad
|
$sectionName !== $this->itemToLoad
|
||||||
&& $sectionConfig->type === $type
|
&& $sectionConfig->type === $type
|
||||||
&& $sectionConfig->owner === $this->getUser()->getUsername()
|
&& $sectionConfig->owner === $this->getUser()->getUsername()
|
||||||
|
&& !in_array($sectionName, $children, true)
|
||||||
) {
|
) {
|
||||||
$names[] = $sectionName;
|
$names[] = $sectionName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
foreach ($this->getUserConfig() as $sectionName => $sectionConfig) {
|
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;
|
$names[] = $sectionName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Ensure that it's not possible to produce circular references
|
|
||||||
return $names;
|
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
|
* Populate the form with the given navigation item's config
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue