NavigationConfigForm: Add method listAvailableParents()

refs #5600
This commit is contained in:
Johannes Meyer 2015-09-17 13:45:47 +02:00
parent f8d53c1d07
commit 6d74373276
1 changed files with 40 additions and 0 deletions

View File

@ -177,6 +177,46 @@ class NavigationConfigForm extends ConfigForm
return $this->itemTypes ?: array();
}
/**
* Return a list of available parent items for the given type of navigation item
*
* @return array
*/
public function listAvailableParents($type)
{
$shared = false;
if (($checkbox = $this->getElement('shared')) !== null) {
if ($checkbox->isChecked()) {
$shared = true;
} else {
$requestData = $this->getRequestData();
$shared = isset($requestData['shared']) && $requestData['shared'];
}
}
$names = array();
if ($shared) {
foreach ($this->getShareConfig() as $sectionName => $sectionConfig) {
if (
$sectionName !== $this->itemToLoad
&& $sectionConfig->type === $type
&& $sectionConfig->owner === $this->getUser()->getUsername()
) {
$names[] = $sectionName;
}
}
} else {
foreach ($this->getUserConfig() as $sectionName => $sectionConfig) {
if ($sectionName !== $this->itemToLoad && $sectionConfig->type === $type) {
$names[] = $sectionName;
}
}
}
// TODO: Ensure that it's not possible to produce circular references
return $names;
}
/**
* Populate the form with the given navigation item's config
*