diff --git a/src/Hackspace/Bundle/CalciferBundle/Controller/LocationController.php b/src/Hackspace/Bundle/CalciferBundle/Controller/LocationController.php index 64b174a..a9ec487 100755 --- a/src/Hackspace/Bundle/CalciferBundle/Controller/LocationController.php +++ b/src/Hackspace/Bundle/CalciferBundle/Controller/LocationController.php @@ -143,8 +143,18 @@ class LocationController extends Controller } if ($location->name != $request->get('name')) { - $location->name = $request->get('name'); - $location->slug = $location->generateSlug($location->name, $em); + // someone changed the name of the location, lets check if the location already exists + $new_location = $repo->findOneBy(['name' => $request->get('name')]); + if (is_null($new_location)) { + $location->name = $request->get('name'); + $location->slug = $location->generateSlug($location->name, $em); + } else { + $request->getSession()->getFlashBag()->add( + 'error', + 'Ort mit diesem Namen existiert bereits.' + ); + return $this->redirect($this->generateUrl('location_edit', array('slug' => $location->slug))); + } } $location->streetaddress = $request->get('streetaddress'); $location->streetnumber = $request->get('streetnumber'); diff --git a/src/Hackspace/Bundle/CalciferBundle/Resources/views/Location/edit.html.twig b/src/Hackspace/Bundle/CalciferBundle/Resources/views/Location/edit.html.twig index 6eb61de..5142616 100644 --- a/src/Hackspace/Bundle/CalciferBundle/Resources/views/Location/edit.html.twig +++ b/src/Hackspace/Bundle/CalciferBundle/Resources/views/Location/edit.html.twig @@ -29,6 +29,17 @@