Skip to content

Commit

Permalink
feature #163 Add flash messages (voronkovich, javiereguiluz)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
javiereguiluz committed Sep 7, 2015
2 parents 7f2ef8b + 3eefa76 commit 53be86f
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 0 deletions.
12 changes: 12 additions & 0 deletions app/Resources/translations/messages.en.xliff
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,18 @@
<source>post.no_posts_found</source>
<target>No posts found.</target>
</trans-unit>
<trans-unit id="post.created_successfully">
<source>post.created_successfully</source>
<target>Post created successfully!</target>
</trans-unit>
<trans-unit id="post.updated_successfully">
<source>post.updated_successfully</source>
<target>Post updated successfully!</target>
</trans-unit>
<trans-unit id="post.deleted_successfully">
<source>post.deleted_successfully</source>
<target>Post deleted successfully!</target>
</trans-unit>

<trans-unit id="help.app_description">
<source>help.app_description</source>
Expand Down
11 changes: 11 additions & 0 deletions app/Resources/translations/messages.ru.xliff
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,17 @@
<trans-unit id="post.no_posts_found">
<source>post.no_posts_found</source>
<target>Ни одной записи не найдено.</target>
<trans-unit id="post.created_successfully">
<source>post.created_successfully</source>
<target>Запись успешно создана!</target>
</trans-unit>
<trans-unit id="post.updated_successfully">
<source>post.updated_successfully</source>
<target>Запись успешно обновлена!</target>
</trans-unit>
<trans-unit id="post.deleted_successfully">
<source>post.deleted_successfully</source>
<target>Запись успешно удалена!</target>
</trans-unit>

<trans-unit id="help.app_description">
Expand Down
2 changes: 2 additions & 0 deletions app/Resources/views/admin/blog/edit.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
{% block main %}
<h1>{{ 'title.edit_post'|trans({'%id%': post.id}) }}</h1>

{{ include('default/_flash_messages.html.twig') }}

{{ include('admin/blog/_form.html.twig', {
form: edit_form,
button_label: 'action.save'|trans,
Expand Down
2 changes: 2 additions & 0 deletions app/Resources/views/admin/blog/index.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
{% block main %}
<h1>{{ 'title.post_list'|trans }}</h1>

{{ include('default/_flash_messages.html.twig') }}

<table class="table table-striped">
<thead>
<tr>
Expand Down
14 changes: 14 additions & 0 deletions app/Resources/views/default/_flash_messages.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{% if app.session.started %}
<div class="messages">
{% for message in app.session.flashBag.get('success') %}
{# Bootstrap alert, see http://getbootstrap.com/components/#alerts #}
<div class="alert alert-dismissible alert-success" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>

{{ message|trans }}
</div>
{% endfor %}
</div>
{% endif %}
10 changes: 10 additions & 0 deletions src/AppBundle/Controller/Admin/BlogController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

Expand Down Expand Up @@ -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()));
}

Expand Down Expand Up @@ -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');
Expand Down

0 comments on commit 53be86f

Please sign in to comment.