NavigationConfigForm: Automatically share a parent's entire children

refs #5600
This commit is contained in:
Johannes Meyer 2015-09-18 16:08:58 +02:00
parent c077dbd15a
commit 9574f80160

View File

@ -317,10 +317,11 @@ class NavigationConfigForm extends ConfigForm
$config = $this->getConfigForItem($name); $config = $this->getConfigForItem($name);
if ($config === null) { if ($config === null) {
throw new NotFoundError('No navigation item called "%s" found', $name); throw new NotFoundError('No navigation item called "%s" found', $name);
} else {
$itemConfig = $config->getSection($name);
} }
$itemConfig = $config->getSection($name); $shared = false;
if ($this->hasBeenShared($name)) { if ($this->hasBeenShared($name)) {
if (isset($data['parent']) && $data['parent'] if (isset($data['parent']) && $data['parent']
? !$this->hasBeenShared($data['parent']) ? !$this->hasBeenShared($data['parent'])
@ -336,6 +337,7 @@ class NavigationConfigForm extends ConfigForm
$this->secondaryConfig = $config; $this->secondaryConfig = $config;
$config = $this->getShareConfig(); $config = $this->getShareConfig();
$data['owner'] = $this->getUser()->getUsername(); $data['owner'] = $this->getUser()->getUsername();
$shared = true;
} else { } else {
unset($data['users']); unset($data['users']);
unset($data['groups']); unset($data['groups']);
@ -352,7 +354,6 @@ class NavigationConfigForm extends ConfigForm
$oldName = null; $oldName = null;
if (isset($data['name'])) { if (isset($data['name'])) {
if ($data['name'] !== $name) { if ($data['name'] !== $name) {
$config->removeSection($name);
$oldName = $name; $oldName = $name;
$name = $data['name']; $name = $data['name'];
} }
@ -360,6 +361,23 @@ class NavigationConfigForm extends ConfigForm
unset($data['name']); unset($data['name']);
} }
$itemConfig->merge($data);
foreach ($itemConfig->toArray() as $k => $v) {
if ($v === null) {
unset($itemConfig->$k);
}
}
if ($shared) {
// Share all descendant children
foreach ($this->getFlattenedChildren($oldName ?: $name) as $child) {
$childConfig = $this->secondaryConfig->getSection($child);
$this->secondaryConfig->removeSection($child);
$childConfig->owner = $this->getUser()->getUsername();
$config->setSection($child, $childConfig);
}
}
if ($oldName) { if ($oldName) {
// Update the parent name on all direct children // Update the parent name on all direct children
foreach ($config as $sectionConfig) { foreach ($config as $sectionConfig) {
@ -367,13 +385,12 @@ class NavigationConfigForm extends ConfigForm
$sectionConfig->parent = $name; $sectionConfig->parent = $name;
} }
} }
$config->removeSection($name);
} }
$itemConfig->merge($data); if ($this->secondaryConfig !== null) {
foreach ($itemConfig->toArray() as $k => $v) { $this->secondaryConfig->removeSection($oldName ?: $name);
if ($v === null) {
unset($itemConfig->$k);
}
} }
$config->setSection($name, $itemConfig); $config->setSection($name, $itemConfig);