Prevent an update of a location when there is a location with the same name.
Fixes #23
This commit is contained in:
parent
97a71875e9
commit
175f99809d
2 changed files with 23 additions and 2 deletions
|
@ -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');
|
||||
|
|
|
@ -29,6 +29,17 @@
|
|||
<div class="ui column">
|
||||
<form method="post"
|
||||
action="{{ path('location_update',{'slug':entity.slug}) }}">
|
||||
{% set errors = app.session.flashbag.get('error') %}
|
||||
{% if errors|length > 0 %}
|
||||
<div class="ui error message">
|
||||
<div class="header">Bitte korrigiere folgende Fehler:</div>
|
||||
<ul class="list">
|
||||
{% for flashMessage in errors %}
|
||||
<li>{{ flashMessage }}</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
{% endif %}
|
||||
<div class="ui form segment">
|
||||
<div class="field">
|
||||
<label class="" for="location-name">Name</label>
|
||||
|
|
Reference in a new issue