Skip to content

Commit

Permalink
NavigationConfigForm: Require argument $type in method getShareConfig()
Browse files Browse the repository at this point in the history
refs #10246
  • Loading branch information
Johannes Meyer committed Sep 29, 2015
1 parent f60a8ef commit 6fdfef4
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions application/forms/Navigation/NavigationConfigForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,20 @@ public function setShareConfig(Config $config)
/**
* Return the shared navigation configuration
*
* @param string $type
*
* @return Config
*/
public function getShareConfig()
public function getShareConfig($type = null)
{
if ($this->shareConfig === null) {
if ($type === null) {
throw new ProgrammingError('You need to pass a type if no share configuration is set');
}

$this->setShareConfig($this->getItemConfig($type));
}

return $this->shareConfig;
}

Expand Down Expand Up @@ -200,10 +210,9 @@ public function listAvailableParents($type, $owner = null)
$children = $this->itemToLoad ? $this->getFlattenedChildren($this->itemToLoad) : array();

$names = array();
foreach ($this->getShareConfig() as $sectionName => $sectionConfig) {
foreach ($this->getShareConfig($type) as $sectionName => $sectionConfig) {
if (
$sectionName !== $this->itemToLoad
&& $sectionConfig->type === $type
&& $sectionConfig->owner === ($owner ?: $this->getUser()->getUsername())
&& !in_array($sectionName, $children, true)
) {
Expand Down Expand Up @@ -292,15 +301,15 @@ public function add(array $data)
if ((isset($data['users']) && $data['users']) || (isset($data['groups']) && $data['groups'])) {
if ($this->getUser()->can('application/share/navigation')) {
$data['owner'] = $this->getUser()->getUsername();
$config = $this->getShareConfig();
$config = $this->getShareConfig($data['type']);
$shared = true;
} else {
unset($data['users']);
unset($data['groups']);
}
} elseif (isset($data['parent']) && $data['parent'] && $this->hasBeenShared($data['parent'])) {
} elseif (isset($data['parent']) && $data['parent'] && $this->hasBeenShared($data['parent'], $data['type'])) {
$data['owner'] = $this->getUser()->getUsername();
$config = $this->getShareConfig();
$config = $this->getShareConfig($data['type']);
$shared = true;
}

Expand All @@ -310,7 +319,7 @@ public function add(array $data)
if ($shared) {
$exists = $this->getUserConfig($data['type'])->hasSection($itemName);
} else {
$exists = (bool) $this->getShareConfig()
$exists = (bool) $this->getShareConfig($data['type'])
->select()
->where('name', $itemName)
->where('owner', $this->getUser()->getUsername())
Expand Down Expand Up @@ -774,12 +783,13 @@ protected function getConfigForItem($name)
* Return whether the given navigation item has been shared
*
* @param string $name
* @param string $type
*
* @return bool
*/
protected function hasBeenShared($name)
protected function hasBeenShared($name, $type = null)
{
return $this->getConfigForItem($name) === $this->getShareConfig();
return $this->getShareConfig($type) === $this->getConfigForItem($name);
}

/**
Expand Down

0 comments on commit 6fdfef4

Please sign in to comment.