aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/CoreBundle
diff options
context:
space:
mode:
authorJeremy Benoist <jeremy.benoist@gmail.com>2016-10-01 14:51:54 +0200
committerJeremy Benoist <jeremy.benoist@gmail.com>2016-10-01 14:58:48 +0200
commit40e219622a2c416ab36cb39b26a5e1354e4438cc (patch)
tree878fb4e50ecee04603f8a05dec04f9a4b8662d18 /src/Wallabag/CoreBundle
parent114c55c0a6eade2ba6c53fe25f61cc58cca91620 (diff)
downloadwallabag-40e219622a2c416ab36cb39b26a5e1354e4438cc.tar.gz
wallabag-40e219622a2c416ab36cb39b26a5e1354e4438cc.tar.zst
wallabag-40e219622a2c416ab36cb39b26a5e1354e4438cc.zip
Customize errors templates
All error goes to the same template which only display the error message and the status code.
Diffstat (limited to 'src/Wallabag/CoreBundle')
-rw-r--r--src/Wallabag/CoreBundle/Controller/ExceptionController.php40
-rw-r--r--src/Wallabag/CoreBundle/ParamConverter/UsernameRssTokenConverter.php7
-rw-r--r--src/Wallabag/CoreBundle/Resources/config/services.yml6
-rw-r--r--src/Wallabag/CoreBundle/Resources/views/themes/baggy/Exception/error.html.twig24
-rw-r--r--src/Wallabag/CoreBundle/Resources/views/themes/material/Exception/error.html.twig30
5 files changed, 103 insertions, 4 deletions
diff --git a/src/Wallabag/CoreBundle/Controller/ExceptionController.php b/src/Wallabag/CoreBundle/Controller/ExceptionController.php
new file mode 100644
index 00000000..abfa9c2f
--- /dev/null
+++ b/src/Wallabag/CoreBundle/Controller/ExceptionController.php
@@ -0,0 +1,40 @@
1<?php
2
3namespace Wallabag\CoreBundle\Controller;
4
5use Symfony\Bundle\TwigBundle\Controller\ExceptionController as BaseExceptionController;
6use Symfony\Component\HttpFoundation\Request;
7
8/**
9 * This controller allow us to customize the error template.
10 * The only modified line from the parent template is for "WallabagCoreBundle".
11 */
12class ExceptionController extends BaseExceptionController
13{
14 protected function findTemplate(Request $request, $format, $code, $showException)
15 {
16 $name = $showException ? 'exception' : 'error';
17 if ($showException && 'html' == $format) {
18 $name = 'exception_full';
19 }
20
21 // For error pages, try to find a template for the specific HTTP status code and format
22 if (!$showException) {
23 $template = sprintf('WallabagCoreBundle:Exception:%s.%s.twig', $name, $format);
24 if ($this->templateExists($template)) {
25 return $template;
26 }
27 }
28
29 // try to find a template for the given format
30 $template = sprintf('@Twig/Exception/%s.%s.twig', $name, $format);
31 if ($this->templateExists($template)) {
32 return $template;
33 }
34
35 // default to a generic HTML exception
36 $request->setRequestFormat('html');
37
38 return sprintf('@Twig/Exception/%s.html.twig', $showException ? 'exception_full' : $name);
39 }
40}
diff --git a/src/Wallabag/CoreBundle/ParamConverter/UsernameRssTokenConverter.php b/src/Wallabag/CoreBundle/ParamConverter/UsernameRssTokenConverter.php
index 6ea2a4f3..40b5673d 100644
--- a/src/Wallabag/CoreBundle/ParamConverter/UsernameRssTokenConverter.php
+++ b/src/Wallabag/CoreBundle/ParamConverter/UsernameRssTokenConverter.php
@@ -49,7 +49,7 @@ class UsernameRssTokenConverter implements ParamConverterInterface
49 $em = $this->registry->getManagerForClass($configuration->getClass()); 49 $em = $this->registry->getManagerForClass($configuration->getClass());
50 50
51 // Check, if class name is what we need 51 // Check, if class name is what we need
52 if ('Wallabag\UserBundle\Entity\User' !== $em->getClassMetadata($configuration->getClass())->getName()) { 52 if (null !== $em && 'Wallabag\UserBundle\Entity\User' !== $em->getClassMetadata($configuration->getClass())->getName()) {
53 return false; 53 return false;
54 } 54 }
55 55
@@ -69,9 +69,8 @@ class UsernameRssTokenConverter implements ParamConverterInterface
69 $username = $request->attributes->get('username'); 69 $username = $request->attributes->get('username');
70 $rssToken = $request->attributes->get('token'); 70 $rssToken = $request->attributes->get('token');
71 71
72 // Check, if route attributes exists 72 if (!$request->attributes->has('username') || !$request->attributes->has('token')) {
73 if (null === $username || null === $rssToken) { 73 return false;
74 throw new \InvalidArgumentException('Route attribute is missing');
75 } 74 }
76 75
77 // Get actual entity manager for class 76 // Get actual entity manager for class
diff --git a/src/Wallabag/CoreBundle/Resources/config/services.yml b/src/Wallabag/CoreBundle/Resources/config/services.yml
index 23e6d3ca..a769b07e 100644
--- a/src/Wallabag/CoreBundle/Resources/config/services.yml
+++ b/src/Wallabag/CoreBundle/Resources/config/services.yml
@@ -133,3 +133,9 @@ services:
133 host: '%redis_host%' 133 host: '%redis_host%'
134 port: '%redis_port%' 134 port: '%redis_port%'
135 schema: tcp 135 schema: tcp
136
137 wallabag_core.exception_controller:
138 class: Wallabag\CoreBundle\Controller\ExceptionController
139 arguments:
140 - '@twig'
141 - '%kernel.debug%'
diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Exception/error.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Exception/error.html.twig
new file mode 100644
index 00000000..b52634fd
--- /dev/null
+++ b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Exception/error.html.twig
@@ -0,0 +1,24 @@
1{% extends "WallabagCoreBundle::layout.html.twig" %}
2
3{% block title %}{{ 'error.page_title'|trans }}{% endblock %}
4
5{% block body_class %}login{% endblock %}
6
7{% block menu %}{% endblock %}
8{% block messages %}{% endblock %}
9{% block header %}{% endblock %}
10
11{% block content %}
12<main class="valign-wrapper">
13 <div class="valign row">
14 <div class="card sw">
15 <div class="center"><img src="{{ asset('bundles/wallabagcore/themes/_global/img/logo-w.png') }}" alt="wallabag logo" /></div>
16 <h2>{{ status_code }}: {{ status_text }}</h2>
17 <p>{{ exception.message }}</p>
18 </div>
19 </div>
20</main>
21{% endblock %}
22
23{% block footer %}
24{% endblock %}
diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/material/Exception/error.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/material/Exception/error.html.twig
new file mode 100644
index 00000000..6be78edb
--- /dev/null
+++ b/src/Wallabag/CoreBundle/Resources/views/themes/material/Exception/error.html.twig
@@ -0,0 +1,30 @@
1{% extends "WallabagCoreBundle::layout.html.twig" %}
2
3{% block title %}{{ 'error.page_title'|trans }}{% endblock %}
4
5{% block body_class %}login{% endblock %}
6
7{% block menu %}{% endblock %}
8{% block messages %}{% endblock %}
9
10{% block content %}
11<main class="valign-wrapper">
12 <div class="valign row">
13 <div class="card sw">
14 <div class="center"><img src="{{ asset('bundles/wallabagcore/themes/_global/img/logo-other_themes.png') }}" alt="wallabag logo" /></div>
15 <div class="card-content">
16 <div class="row">
17 <h5>{{ status_code }}: {{ status_text }}</h5>
18 <p>{{ exception.message }}</p>
19 {# {% for trace in exception.trace %}
20 <p>{{ trace.class }} - {{ trace.type }} - {{ trace.file }} - {{ trace.line }}</p>
21 {% endfor %} #}
22 </div>
23 </div>
24 </div>
25 </div>
26</main>
27{% endblock %}
28
29{% block footer %}
30{% endblock %}