diff --git a/app/Resources/translations/messages.en.xliff b/app/Resources/translations/messages.en.xliff index ed4fe6838..02a1ec5ea 100644 --- a/app/Resources/translations/messages.en.xliff +++ b/app/Resources/translations/messages.en.xliff @@ -199,6 +199,18 @@ post.no_posts_found No posts found. + + post.created_successfully + Post created successfully! + + + post.updated_successfully + Post updated successfully! + + + post.deleted_successfully + Post deleted successfully! + help.app_description diff --git a/app/Resources/translations/messages.ru.xliff b/app/Resources/translations/messages.ru.xliff index f5b3f1e17..4036ce477 100644 --- a/app/Resources/translations/messages.ru.xliff +++ b/app/Resources/translations/messages.ru.xliff @@ -198,6 +198,17 @@ post.no_posts_found Ни одной записи не найдено. + + post.created_successfully + Запись успешно создана! + + + post.updated_successfully + Запись успешно обновлена! + + + post.deleted_successfully + Запись успешно удалена! diff --git a/app/Resources/views/admin/blog/edit.html.twig b/app/Resources/views/admin/blog/edit.html.twig index 5fee71964..20d3a63ad 100644 --- a/app/Resources/views/admin/blog/edit.html.twig +++ b/app/Resources/views/admin/blog/edit.html.twig @@ -5,6 +5,8 @@ {% block main %}

{{ 'title.edit_post'|trans({'%id%': post.id}) }}

+ {{ include('default/_flash_messages.html.twig') }} + {{ include('admin/blog/_form.html.twig', { form: edit_form, button_label: 'action.save'|trans, diff --git a/app/Resources/views/admin/blog/index.html.twig b/app/Resources/views/admin/blog/index.html.twig index 7a0442a50..29348e01c 100644 --- a/app/Resources/views/admin/blog/index.html.twig +++ b/app/Resources/views/admin/blog/index.html.twig @@ -5,6 +5,8 @@ {% block main %}

{{ 'title.post_list'|trans }}

+ {{ include('default/_flash_messages.html.twig') }} + diff --git a/app/Resources/views/default/_flash_messages.html.twig b/app/Resources/views/default/_flash_messages.html.twig new file mode 100644 index 000000000..e667c37e3 --- /dev/null +++ b/app/Resources/views/default/_flash_messages.html.twig @@ -0,0 +1,14 @@ +{% if app.session.started %} +
+ {% for message in app.session.flashBag.get('success') %} + {# Bootstrap alert, see http://getbootstrap.com/components/#alerts #} + + {% endfor %} +
+{% endif %} diff --git a/src/AppBundle/Controller/Admin/BlogController.php b/src/AppBundle/Controller/Admin/BlogController.php index b229c7a3e..f39e80269 100644 --- a/src/AppBundle/Controller/Admin/BlogController.php +++ b/src/AppBundle/Controller/Admin/BlogController.php @@ -87,6 +87,12 @@ public function newAction(Request $request) $em->persist($post); $em->flush(); + // Flash messages are used to notify the user about the result of the + // actions. They are deleted automatically from the session as soon + // as they are accessed. + // See http://symfony.com/doc/current/book/controller.html#flash-messages + $this->addFlash('success', 'post.created_successfully'); + return $this->redirectToRoute('admin_post_index'); } @@ -142,6 +148,8 @@ public function editAction(Post $post, Request $request) $post->setSlug($this->get('slugger')->slugify($post->getTitle())); $em->flush(); + $this->addFlash('success', 'post.updated_successfully'); + return $this->redirectToRoute('admin_post_edit', array('id' => $post->getId())); } @@ -173,6 +181,8 @@ public function deleteAction(Request $request, Post $post) $em->remove($post); $em->flush(); + + $this->addFlash('success', 'post.deleted_successfully'); } return $this->redirectToRoute('admin_post_index');