Added name duplication check when creating a variable
This commit is contained in:
@@ -83,7 +83,9 @@ class VariablesController extends BaseAdminController
|
||||
->setValue($data['value'])
|
||||
->setLocale($data["locale"])
|
||||
->setTitle($data['title'])
|
||||
;
|
||||
->setHidden($data['hidden'])
|
||||
->setSecured($data['secured'])
|
||||
;
|
||||
|
||||
$this->dispatch(TheliaEvents::CONFIG_CREATE, $createEvent);
|
||||
|
||||
@@ -288,7 +290,7 @@ class VariablesController extends BaseAdminController
|
||||
if (null !== $response = $this->checkAuth("admin.configuration.variables.delete")) return $response;
|
||||
|
||||
// Get the config id, and dispatch the delet request
|
||||
$event = new ConfigDeleteEvent($this->getRequest()->get('id'));
|
||||
$event = new ConfigDeleteEvent($this->getRequest()->get('variable_id'));
|
||||
|
||||
$this->dispatch(TheliaEvents::CONFIG_DELETE, $event);
|
||||
|
||||
|
||||
@@ -120,6 +120,29 @@ class BaseController extends ContainerAware
|
||||
return $request->getSession();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all errors that occured in a form
|
||||
*
|
||||
* @param \Symfony\Component\Form\Form $form
|
||||
* @return string the error string
|
||||
*/
|
||||
private function getErrorMessages(\Symfony\Component\Form\Form $form) {
|
||||
|
||||
$errors = '';
|
||||
|
||||
foreach ($form->getErrors() as $key => $error) {
|
||||
$errors .= $error->getMessage() . ', ';
|
||||
}
|
||||
|
||||
foreach ($form->all() as $child) {
|
||||
if (!$child->isValid()) {
|
||||
$errors .= $this->getErrorMessages($child) . ', ';
|
||||
}
|
||||
}
|
||||
|
||||
return rtrim($errors, ', ');
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate a BaseForm
|
||||
*
|
||||
@@ -138,10 +161,12 @@ class BaseController extends ContainerAware
|
||||
|
||||
if ($form->isValid()) {
|
||||
return $form;
|
||||
} else {
|
||||
throw new FormValidationException("Missing or invalid data");
|
||||
}
|
||||
} else {
|
||||
else {
|
||||
throw new FormValidationException(sprintf("Missing or invalid data: %s", $this->getErrorMessages($form)));
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new FormValidationException(sprintf("Wrong form method, %s expected.", $expectedMethod));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user