From 6d743732760b773a5126d0bfd97c7b048b10c528 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Thu, 17 Sep 2015 13:45:47 +0200 Subject: [PATCH] NavigationConfigForm: Add method listAvailableParents() refs #5600 --- .../forms/Navigation/NavigationConfigForm.php | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/application/forms/Navigation/NavigationConfigForm.php b/application/forms/Navigation/NavigationConfigForm.php index 78be4d4c6..a5b01e490 100644 --- a/application/forms/Navigation/NavigationConfigForm.php +++ b/application/forms/Navigation/NavigationConfigForm.php @@ -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 *