Skip to content

Commit 7fe9eef

Browse files
author
Leny BERNARD
committed
get back twig extension to continue to render alerts with {{ app.session|alertify|raw }}
1 parent 3fd5ebb commit 7fe9eef

File tree

4 files changed

+78
-2
lines changed

4 files changed

+78
-2
lines changed

Handler/AlertifySessionHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public function handle($session)
7878
*
7979
* @return array
8080
**/
81-
public function getDefaultParametersFromContext($context = null)
81+
protected function getDefaultParametersFromContext($context = null)
8282
{
8383
if (count($this->defaultParameters['contexts'])) {
8484
//If context is not given, just take the default one

Resources/config/services.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
55

66
<parameters>
7+
<parameter key="alertify.twig.extension.class">Troopers\AlertifyBundle\Twig\Extension\AlertifyExtension</parameter>
78
<parameter key="alertify.handler.session.class">Troopers\AlertifyBundle\Handler\AlertifySessionHandler</parameter>
89
<parameter key="alertify.helper.class">Troopers\AlertifyBundle\Helper\AlertifyHelper</parameter>
910
<parameter key="alertify.event_listener">Troopers\AlertifyBundle\EventListener\AlertifyListener</parameter>
@@ -17,5 +18,15 @@
1718
<argument type="service" id="twig" />
1819
<argument>%troopers_alertify%</argument>
1920
</service>
21+
<service id="troopers_alertifybundle.event_listener" class="%alertify.event_listener%">
22+
<tag name="kernel.event_subscriber" />
23+
<argument type="service" id="session" />
24+
<argument type="service" id="troopers_alertifybundle.session_handler" />
25+
</service>
26+
<service id="troopers_alertifybundle.twig.extension" class="%alertify.twig.extension.class%">
27+
<tag name="twig.extension" />
28+
<argument type="service" id="troopers_alertifybundle.session_handler" />
29+
</service>
30+
2031
</services>
2132
</container>

Resources/views/pushjs.html.twig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
{{ dump(options) }}
21
<script type="text/javascript">
32
Push.create('{{ title|default(body)|trans({}, translationDomain|default('messages'))|striptags }}', {
43
body: '{{ title|default(false) ? body|trans({}, translationDomain|default('messages'))|striptags : null }}',
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
3+
namespace Troopers\AlertifyBundle\Twig\Extension;
4+
5+
use Symfony\Component\HttpFoundation\Session\Session;
6+
use Troopers\AlertifyBundle\Handler\AlertifySessionHandler;
7+
8+
/**
9+
* AlertifyExtension.
10+
*/
11+
class AlertifyExtension extends \Twig_Extension implements \Twig_Extension_InitRuntimeInterface
12+
{
13+
/**
14+
* @var AlertifySessionHandler
15+
*/
16+
private $alertifySessionHandler;
17+
18+
/**
19+
* AlertifyExtension constructor.
20+
*
21+
* @param AlertifySessionHandler $alertifySessionHandler
22+
*/
23+
public function __construct(AlertifySessionHandler $alertifySessionHandler)
24+
{
25+
$this->alertifySessionHandler = $alertifySessionHandler;
26+
}
27+
28+
/**
29+
* {@inheritdoc}
30+
*/
31+
public function initRuntime(\Twig_Environment $environment)
32+
{
33+
$this->environment = $environment;
34+
}
35+
36+
/**
37+
* {@inheritdoc}
38+
*/
39+
public function getName()
40+
{
41+
return 'alertify';
42+
}
43+
44+
/**
45+
* {@inheritdoc}
46+
*/
47+
public function getFilters()
48+
{
49+
return [
50+
new \Twig_SimpleFilter('alertify', [$this, 'alertifyFilter'], ['needs_environment' => true, 'is_safe' => ['html']]),
51+
];
52+
}
53+
54+
/**
55+
* Alertify filter.
56+
*
57+
* @param \Twig_Environment $environment
58+
* @param Session $session
59+
*
60+
* @return string
61+
*/
62+
public function alertifyFilter($environment, Session $session)
63+
{
64+
return $this->alertifySessionHandler->handle($session);
65+
}
66+
}

0 commit comments

Comments
 (0)