Fix error validation for SAP battery. #524
This commit is contained in:
parent
0752fe3726
commit
ac2138c1b1
1 changed files with 17 additions and 9 deletions
|
|
@ -152,19 +152,26 @@ class SAPBatteryController extends Controller
|
|||
{
|
||||
$this->denyAccessUnlessGranted('sap_battery.add', null, 'No access.');
|
||||
|
||||
// initialize error list
|
||||
$error_array = [];
|
||||
|
||||
// create new row
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$row = new SAPBattery();
|
||||
|
||||
$id = trim($req->request->get('id'));
|
||||
if (empty($id))
|
||||
$error_array['id'] = 'SAP code is required.';
|
||||
|
||||
// set and save values
|
||||
$row->setID($req->request->get('id'));
|
||||
$row->setID($id);
|
||||
|
||||
// custom validation for battery brand
|
||||
$brand = $em->getRepository(SAPBatteryBrand::class)
|
||||
->find($req->request->get('brand'));
|
||||
|
||||
if (empty($brand))
|
||||
$error_array['brannd'] = 'Invalid brand selected.';
|
||||
$error_array['brand'] = 'Invalid brand selected.';
|
||||
else
|
||||
$row->setBrand($brand);
|
||||
|
||||
|
|
@ -180,9 +187,6 @@ class SAPBatteryController extends Controller
|
|||
// validate
|
||||
$errors = $validator->validate($row);
|
||||
|
||||
// initialize error list
|
||||
$error_array = [];
|
||||
|
||||
// add errors to list
|
||||
foreach ($errors as $error) {
|
||||
$error_array[$error->getPropertyPath()] = $error->getMessage();
|
||||
|
|
@ -247,8 +251,15 @@ class SAPBatteryController extends Controller
|
|||
if (empty($row))
|
||||
throw $this->createNotFoundException('The item does not exist');
|
||||
|
||||
// initialize error list
|
||||
$error_array = [];
|
||||
|
||||
$id = trim($req->request->get('id'));
|
||||
if (empty($id))
|
||||
$error_array['id'] = 'SAP code is required.';
|
||||
|
||||
// set and save values
|
||||
$row->setID($req->request->get('id'));
|
||||
$row->setID($id);
|
||||
|
||||
// custom validation for battery brand
|
||||
$brand = $em->getRepository(SAPBatteryBrand::class)
|
||||
|
|
@ -271,9 +282,6 @@ class SAPBatteryController extends Controller
|
|||
// validate
|
||||
$errors = $validator->validate($row);
|
||||
|
||||
// initialize error list
|
||||
$error_array = [];
|
||||
|
||||
// add errors to list
|
||||
foreach ($errors as $error) {
|
||||
$error_array[$error->getPropertyPath()] = $error->getMessage();
|
||||
|
|
|
|||
Loading…
Reference in a new issue