Skip to content

Commit

Permalink
get back twig extension to continue to render alerts with {{ app.sess…
Browse files Browse the repository at this point in the history
…ion|alertify|raw }}
  • Loading branch information
Leny BERNARD committed Oct 19, 2016
1 parent 3fd5ebb commit 7fe9eef
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Handler/AlertifySessionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function handle($session)
*
* @return array
**/
public function getDefaultParametersFromContext($context = null)
protected function getDefaultParametersFromContext($context = null)
{
if (count($this->defaultParameters['contexts'])) {
//If context is not given, just take the default one
Expand Down
11 changes: 11 additions & 0 deletions Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">

<parameters>
<parameter key="alertify.twig.extension.class">Troopers\AlertifyBundle\Twig\Extension\AlertifyExtension</parameter>
<parameter key="alertify.handler.session.class">Troopers\AlertifyBundle\Handler\AlertifySessionHandler</parameter>
<parameter key="alertify.helper.class">Troopers\AlertifyBundle\Helper\AlertifyHelper</parameter>
<parameter key="alertify.event_listener">Troopers\AlertifyBundle\EventListener\AlertifyListener</parameter>
Expand All @@ -17,5 +18,15 @@
<argument type="service" id="twig" />
<argument>%troopers_alertify%</argument>
</service>
<service id="troopers_alertifybundle.event_listener" class="%alertify.event_listener%">
<tag name="kernel.event_subscriber" />
<argument type="service" id="session" />
<argument type="service" id="troopers_alertifybundle.session_handler" />
</service>
<service id="troopers_alertifybundle.twig.extension" class="%alertify.twig.extension.class%">
<tag name="twig.extension" />
<argument type="service" id="troopers_alertifybundle.session_handler" />
</service>

</services>
</container>
1 change: 0 additions & 1 deletion Resources/views/pushjs.html.twig
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{{ dump(options) }}
<script type="text/javascript">
Push.create('{{ title|default(body)|trans({}, translationDomain|default('messages'))|striptags }}', {
body: '{{ title|default(false) ? body|trans({}, translationDomain|default('messages'))|striptags : null }}',
Expand Down
66 changes: 66 additions & 0 deletions Twig/Extension/AlertifyExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

namespace Troopers\AlertifyBundle\Twig\Extension;

use Symfony\Component\HttpFoundation\Session\Session;
use Troopers\AlertifyBundle\Handler\AlertifySessionHandler;

/**
* AlertifyExtension.
*/
class AlertifyExtension extends \Twig_Extension implements \Twig_Extension_InitRuntimeInterface
{
/**
* @var AlertifySessionHandler
*/
private $alertifySessionHandler;

/**
* AlertifyExtension constructor.
*
* @param AlertifySessionHandler $alertifySessionHandler
*/
public function __construct(AlertifySessionHandler $alertifySessionHandler)
{
$this->alertifySessionHandler = $alertifySessionHandler;
}

/**
* {@inheritdoc}
*/
public function initRuntime(\Twig_Environment $environment)
{
$this->environment = $environment;
}

/**
* {@inheritdoc}
*/
public function getName()
{
return 'alertify';
}

/**
* {@inheritdoc}
*/
public function getFilters()
{
return [
new \Twig_SimpleFilter('alertify', [$this, 'alertifyFilter'], ['needs_environment' => true, 'is_safe' => ['html']]),
];
}

/**
* Alertify filter.
*
* @param \Twig_Environment $environment
* @param Session $session
*
* @return string
*/
public function alertifyFilter($environment, Session $session)
{
return $this->alertifySessionHandler->handle($session);
}
}

0 comments on commit 7fe9eef

Please sign in to comment.