Skip to content

Commit

Permalink
NavigationConfigForm: Add method listAvailableParents()
Browse files Browse the repository at this point in the history
refs #5600
  • Loading branch information
Johannes Meyer committed Sep 17, 2015
1 parent f8d53c1 commit 6d74373
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions application/forms/Navigation/NavigationConfigForm.php
Expand Up @@ -177,6 +177,46 @@ public function getItemTypes()
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
*
Expand Down

0 comments on commit 6d74373

Please sign in to comment.