Skip to content

Commit 53be86f

Browse files
committed
feature #163 Add flash messages (voronkovich, javiereguiluz)
This PR was merged into the master branch. Discussion ---------- Add flash messages This finishes #158 by simplifying its contents. Commits ------- 3eefa76 Reworded the help note about flash messages 9a8d43d Check if the session exists before reading flash messages d01311b Transformed the macro() of the Flash messages into a regular include() template f481eef Refactored the template code related to macros da04216 Fixed an issue with the translation file after the rebase 51f7262 Restored the content database 7507a50 Simplified the template code used to render flash messages a46c948 Use 'success' as the name of the messages related to success messages 12bd670 Update Russian and English translations 0680841 Show flash messages after creating, updating and deleting posts
2 parents 7f2ef8b + 3eefa76 commit 53be86f

File tree

6 files changed

+51
-0
lines changed

6 files changed

+51
-0
lines changed

app/Resources/translations/messages.en.xliff

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,18 @@
199199
<source>post.no_posts_found</source>
200200
<target>No posts found.</target>
201201
</trans-unit>
202+
<trans-unit id="post.created_successfully">
203+
<source>post.created_successfully</source>
204+
<target>Post created successfully!</target>
205+
</trans-unit>
206+
<trans-unit id="post.updated_successfully">
207+
<source>post.updated_successfully</source>
208+
<target>Post updated successfully!</target>
209+
</trans-unit>
210+
<trans-unit id="post.deleted_successfully">
211+
<source>post.deleted_successfully</source>
212+
<target>Post deleted successfully!</target>
213+
</trans-unit>
202214

203215
<trans-unit id="help.app_description">
204216
<source>help.app_description</source>

app/Resources/translations/messages.ru.xliff

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,17 @@
198198
<trans-unit id="post.no_posts_found">
199199
<source>post.no_posts_found</source>
200200
<target>Ни одной записи не найдено.</target>
201+
<trans-unit id="post.created_successfully">
202+
<source>post.created_successfully</source>
203+
<target>Запись успешно создана!</target>
204+
</trans-unit>
205+
<trans-unit id="post.updated_successfully">
206+
<source>post.updated_successfully</source>
207+
<target>Запись успешно обновлена!</target>
208+
</trans-unit>
209+
<trans-unit id="post.deleted_successfully">
210+
<source>post.deleted_successfully</source>
211+
<target>Запись успешно удалена!</target>
201212
</trans-unit>
202213

203214
<trans-unit id="help.app_description">

app/Resources/views/admin/blog/edit.html.twig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
{% block main %}
66
<h1>{{ 'title.edit_post'|trans({'%id%': post.id}) }}</h1>
77

8+
{{ include('default/_flash_messages.html.twig') }}
9+
810
{{ include('admin/blog/_form.html.twig', {
911
form: edit_form,
1012
button_label: 'action.save'|trans,

app/Resources/views/admin/blog/index.html.twig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
{% block main %}
66
<h1>{{ 'title.post_list'|trans }}</h1>
77

8+
{{ include('default/_flash_messages.html.twig') }}
9+
810
<table class="table table-striped">
911
<thead>
1012
<tr>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{% if app.session.started %}
2+
<div class="messages">
3+
{% for message in app.session.flashBag.get('success') %}
4+
{# Bootstrap alert, see http://getbootstrap.com/components/#alerts #}
5+
<div class="alert alert-dismissible alert-success" role="alert">
6+
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
7+
<span aria-hidden="true">&times;</span>
8+
</button>
9+
10+
{{ message|trans }}
11+
</div>
12+
{% endfor %}
13+
</div>
14+
{% endif %}

src/AppBundle/Controller/Admin/BlogController.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,12 @@ public function newAction(Request $request)
8787
$em->persist($post);
8888
$em->flush();
8989

90+
// Flash messages are used to notify the user about the result of the
91+
// actions. They are deleted automatically from the session as soon
92+
// as they are accessed.
93+
// See http://symfony.com/doc/current/book/controller.html#flash-messages
94+
$this->addFlash('success', 'post.created_successfully');
95+
9096
return $this->redirectToRoute('admin_post_index');
9197
}
9298

@@ -142,6 +148,8 @@ public function editAction(Post $post, Request $request)
142148
$post->setSlug($this->get('slugger')->slugify($post->getTitle()));
143149
$em->flush();
144150

151+
$this->addFlash('success', 'post.updated_successfully');
152+
145153
return $this->redirectToRoute('admin_post_edit', array('id' => $post->getId()));
146154
}
147155

@@ -173,6 +181,8 @@ public function deleteAction(Request $request, Post $post)
173181

174182
$em->remove($post);
175183
$em->flush();
184+
185+
$this->addFlash('success', 'post.deleted_successfully');
176186
}
177187

178188
return $this->redirectToRoute('admin_post_index');

0 commit comments

Comments
 (0)