add form error handle in settings actions
This commit is contained in:
parent
5d3999f766
commit
4385e7a525
|
@ -31,11 +31,28 @@ class NavigationSettingAdminController extends AdminController
|
|||
$eventDispatcher->dispatch($event, NavigationSettingEvent::FORM_INIT_EVENT);
|
||||
|
||||
$form = $builder->getForm();
|
||||
$redirectTo = $request->query->get('redirectTo');
|
||||
$session = $request->getSession();
|
||||
$lastRequestId = sprintf('setting_request_%s_%s', get_class($entity), $entity->getId());
|
||||
$lastRequest = $session->get($lastRequestId);
|
||||
|
||||
if ($lastRequest !== null && !$request->isMethod('POST')) {
|
||||
$fakeRequest = Request::create(
|
||||
uri: $request->getUri(),
|
||||
method: 'POST',
|
||||
parameters: [$form->getName() => $lastRequest]
|
||||
);
|
||||
|
||||
$form->handleRequest($fakeRequest);
|
||||
$session->remove($lastRequestId);
|
||||
}
|
||||
|
||||
if ($request->isMethod('POST')) {
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isValid()) {
|
||||
$entityManager->update($entity);
|
||||
$session->remove($lastRequestId);
|
||||
$entityManager->update($entity);
|
||||
$this->addFlash('success', 'The data has been saved.');
|
||||
|
||||
|
@ -44,13 +61,21 @@ class NavigationSettingAdminController extends AdminController
|
|||
]);
|
||||
}
|
||||
|
||||
$session->set($lastRequestId, $request->request->get('form'));
|
||||
$this->addFlash('warning', 'The form is not valid.');
|
||||
|
||||
return $this->redirect(sprintf(
|
||||
'%s?data-modal=%s',
|
||||
$redirectTo,
|
||||
urlencode($request->getUri())
|
||||
));
|
||||
}
|
||||
|
||||
return $this->render('@Core/setting/navigation_setting_admin/edit.html.twig', [
|
||||
'form' => $form->createView(),
|
||||
'entity' => $entity,
|
||||
'options' => $event->getData()['options'],
|
||||
'redirectTo' => $redirectTo,
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
|
@ -51,24 +51,49 @@ class SettingAdminController extends AdminController
|
|||
$eventDispatcher->dispatch($event, SettingEvent::FORM_INIT_EVENT);
|
||||
|
||||
$form = $builder->getForm();
|
||||
$redirectTo = $request->query->get('redirectTo');
|
||||
$session = $request->getSession();
|
||||
$lastRequestId = sprintf('setting_request_%s_%s', get_class($entity), $entity->getId());
|
||||
$lastRequest = $session->get($lastRequestId);
|
||||
|
||||
if ($lastRequest !== null && !$request->isMethod('POST')) {
|
||||
$fakeRequest = Request::create(
|
||||
uri: $request->getUri(),
|
||||
method: 'POST',
|
||||
parameters: [$form->getName() => $lastRequest]
|
||||
);
|
||||
|
||||
$form->handleRequest($fakeRequest);
|
||||
$session->remove($lastRequestId);
|
||||
}
|
||||
|
||||
if ($request->isMethod('POST')) {
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isValid()) {
|
||||
$entityManager->update($entity);
|
||||
$session->remove($lastRequestId);
|
||||
$entityManager->update($entity);
|
||||
$this->addFlash('success', 'The data has been saved.');
|
||||
|
||||
return $this->redirectToRoute('admin_setting_index');
|
||||
}
|
||||
|
||||
$session->set($lastRequestId, $request->request->get('form'));
|
||||
$this->addFlash('warning', 'The form is not valid.');
|
||||
|
||||
return $this->redirect(sprintf(
|
||||
'%s?data-modal=%s',
|
||||
$redirectTo,
|
||||
urlencode($request->getUri())
|
||||
));
|
||||
}
|
||||
|
||||
return $this->render('@Core/setting/setting_admin/edit.html.twig', [
|
||||
'form' => $form->createView(),
|
||||
'entity' => $entity,
|
||||
'options' => $event->getData()['options'],
|
||||
'redirectTo' => $redirectTo,
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
</button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<form action="{{ path(configuration.pageRoute('inline_edit'), {entity: entity.id, context: context, label: label, redirectTo, redirectTo}|merge(configuration.pageRouteParams('inline_edit'))) }}" id="form-entity-edit" method="POST">
|
||||
<form action="{{ path(configuration.pageRoute('inline_edit'), {entity: entity.id, context: context, label: label, redirectTo: redirectTo}|merge(configuration.pageRouteParams('inline_edit'))) }}" id="form-entity-edit" method="POST">
|
||||
{{ include('@Core/setting/setting_admin/_form.html.twig') }}
|
||||
</form>
|
||||
</div>
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
</button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<form action="{{ path('admin_navigation_setting_edit', {entity: entity.id}) }}" id="form-entity-edit" method="POST">
|
||||
<form action="{{ path('admin_navigation_setting_edit', {entity: entity.id, redirectTo: redirectTo}) }}" id="form-entity-edit" method="POST">
|
||||
{{ include('@Core/setting/navigation_setting_admin/_form.html.twig') }}
|
||||
</form>
|
||||
</div>
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
</button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<form action="{{ path('admin_setting_edit', {entity: entity.id}) }}" id="form-entity-edit" method="POST">
|
||||
<form action="{{ path('admin_setting_edit', {entity: entity.id, redirectTo: redirectTo}) }}" id="form-entity-edit" method="POST">
|
||||
{{ include('@Core/setting/setting_admin/_form.html.twig') }}
|
||||
</form>
|
||||
</div>
|
||||
|
|
|
@ -22,11 +22,11 @@
|
|||
</thead>
|
||||
<tbody>
|
||||
{% for item in pager %}
|
||||
{% set edit = path('admin_setting_edit', {entity: item.id}) %}
|
||||
{% set edit = path('admin_setting_edit', {entity: item.id, redirectTo: app.request.pathInfo}) %}
|
||||
|
||||
<tr>
|
||||
<td class="col-5">
|
||||
<a href="#" data-modal="{{ edit }}" class="font-weight-bold text-body d-block">
|
||||
<a href="#" data-modal="{{ edit }}" data-modal-create class="font-weight-bold text-body d-block">
|
||||
{{ item.label|trans }}
|
||||
</a>
|
||||
</td>
|
||||
|
@ -34,7 +34,7 @@
|
|||
<span class="btn btn-light">{{ item.section|trans }}</span>
|
||||
</td>
|
||||
<td class="col-2 miw-100 text-right">
|
||||
<span data-modal="{{ edit }}" class="btn btn-sm btn-primary mr-1">
|
||||
<span data-modal="{{ edit }}" data-modal-create class="btn btn-sm btn-primary mr-1">
|
||||
<span data-modal="{{ edit }}" class="fa fa-edit"></span>
|
||||
</span>
|
||||
<button type="submit" form="form-delete-{{ item.id }}" class="btn btn-sm btn-danger">
|
||||
|
|
|
@ -54,7 +54,7 @@
|
|||
</thead>
|
||||
<tbody>
|
||||
{% for item in datas.settings %}
|
||||
{% set edit = path('admin_navigation_setting_edit', {entity: item.id}) %}
|
||||
{% set edit = path('admin_navigation_setting_edit', {entity: item.id, redirectTo: app.request.pathInfo}) %}
|
||||
|
||||
<tr data-dblclick="{{ edit }}">
|
||||
<td class="col-5">
|
||||
|
|
Loading…
Reference in a new issue