Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add flash messages #163

Merged
merged 10 commits into from
Sep 7, 2015
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