NavigationConfigForm: Write both configurations in a single "operation"
refs #5600
This commit is contained in:
parent
50cdd0ad15
commit
ac3ef393b5
|
@ -211,23 +211,27 @@ class NavigationController extends Controller
|
||||||
$form = new Form(array(
|
$form = new Form(array(
|
||||||
'onSuccess' => function ($form) use ($navigationConfigForm) {
|
'onSuccess' => function ($form) use ($navigationConfigForm) {
|
||||||
try {
|
try {
|
||||||
if ($navigationConfigForm->unshare($form->getValue('name'))) {
|
$navigationConfigForm->unshare($form->getValue('name'));
|
||||||
Notification::success(sprintf(
|
|
||||||
t('Navigation item "%s" has been unshared'),
|
|
||||||
$form->getValue('name')
|
|
||||||
));
|
|
||||||
} else {
|
|
||||||
Notification::error(sprintf(
|
|
||||||
t('Failed to unshare navigation item "%s"'),
|
|
||||||
$form->getValue('name')
|
|
||||||
));
|
|
||||||
}
|
|
||||||
} catch (NotFoundError $e) {
|
} catch (NotFoundError $e) {
|
||||||
throw $e;
|
throw $e;
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
Notification::error($e->getMessage());
|
Notification::error($e->getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($navigationConfigForm->save()) {
|
||||||
|
Notification::success(sprintf(
|
||||||
|
t('Navigation item "%s" has been unshared'),
|
||||||
|
$form->getValue('name')
|
||||||
|
));
|
||||||
|
} else {
|
||||||
|
// TODO: It failed obviously to write one of the configs, so we're leaving the user in
|
||||||
|
// a inconsistent state. Luckily, it's nothing lost but possibly duplicated...
|
||||||
|
Notification::error(sprintf(
|
||||||
|
t('Failed to unshare navigation item "%s"'),
|
||||||
|
$form->getValue('name')
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
$redirect = $form->getValue('redirect');
|
$redirect = $form->getValue('redirect');
|
||||||
if (! empty($redirect)) {
|
if (! empty($redirect)) {
|
||||||
$form->setRedirectUrl(htmlspecialchars_decode($redirect));
|
$form->setRedirectUrl(htmlspecialchars_decode($redirect));
|
||||||
|
|
|
@ -43,7 +43,7 @@ class ConfigForm extends Form
|
||||||
public function save()
|
public function save()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$this->config->saveIni();
|
$this->writeConfig($this->config);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
$this->addDecorator('ViewScript', array(
|
$this->addDecorator('ViewScript', array(
|
||||||
'viewModule' => 'default',
|
'viewModule' => 'default',
|
||||||
|
@ -58,4 +58,14 @@ class ConfigForm extends Form
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write the configuration to disk
|
||||||
|
*
|
||||||
|
* @param Config $config
|
||||||
|
*/
|
||||||
|
protected function writeConfig(Config $config)
|
||||||
|
{
|
||||||
|
$config->saveIni();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,16 @@ class NavigationConfigForm extends ConfigForm
|
||||||
'dashlet'
|
'dashlet'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The secondary configuration to write
|
||||||
|
*
|
||||||
|
* This is always the reduced configuration and is only written to
|
||||||
|
* disk once the main configuration has been successfully written.
|
||||||
|
*
|
||||||
|
* @var Config
|
||||||
|
*/
|
||||||
|
protected $secondaryConfig;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The navigation item to load when displaying the form for the first time
|
* The navigation item to load when displaying the form for the first time
|
||||||
*
|
*
|
||||||
|
@ -319,6 +329,19 @@ class NavigationConfigForm extends ConfigForm
|
||||||
return $values;
|
return $values;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
protected function writeConfig(Config $config)
|
||||||
|
{
|
||||||
|
parent::writeConfig($config);
|
||||||
|
|
||||||
|
if ($this->secondaryConfig !== null) {
|
||||||
|
$this->config = $this->secondaryConfig; // Causes the config being displayed to the user in case of an error
|
||||||
|
parent::writeConfig($this->secondaryConfig);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a list of available item types
|
* Return a list of available item types
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue