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

made session flashes closeable with configuration #840

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,9 @@ protected function addFlashConfig(ArrayNodeDefinition $rootNode)
->arrayNode('flash')
->addDefaultsIfNotSet()
->children()
->booleanNode('closeable')
->defaultFalse()
->end()
->arrayNode('mapping')
->addDefaultsIfNotSet()
->children()
Expand Down
3 changes: 2 additions & 1 deletion DependencyInjection/MopaBootstrapExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,9 @@ public function load(array $configs, ContainerBuilder $container)
* Flash
*/
if (isset($config['flash'])) {
$mapping = array();
$container->setParameter('mopa_bootstrap.flash.closeable', $config['flash']['closeable']);

$mapping = array();
foreach ($config['flash']['mapping'] as $alertType => $flashTypes) {
foreach ($flashTypes as $type) {
$mapping[$type] = $alertType;
Expand Down
1 change: 1 addition & 0 deletions Resources/config/twig.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

<service id="mopa_bootstrap.twig.extension.bootstrap_flash" class="%mopa_bootstrap.twig.extension.flash.class%">
<argument type="collection" />
<argument>%mopa_bootstrap.flash.closeable%</argument>
<tag name="twig.extension" />
</service>
</services>
Expand Down
1 change: 1 addition & 0 deletions Resources/doc/configuration-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ mopa_bootstrap:
diagnostic_mode: false

flash:
closeable: false
mapping:
# alertType => [flashType1, ..]
success: [success]
Expand Down
2 changes: 1 addition & 1 deletion Resources/views/flash.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
{% set domain = 'FOSUserBundle' %}
{% endif %}
{% for message in messages %}
{{ flash_messages.flash(mapping[type], message, close, use_raw, class, domain) }}
{{ flash_messages.flash(mapping[type], message, mopa_bootstrap_flash_closeable(close), use_raw, class, domain) }}
{% endfor %}
{% endfor %}
{% endif %}
Expand Down
20 changes: 17 additions & 3 deletions Twig/FlashExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,18 @@

namespace Mopa\Bundle\BootstrapBundle\Twig;

use Symfony\Component\HttpFoundation\Response;

/**
* MopaBootstrap Flash Extension.
*
* @author Nikolai Zujev (jaymecd) <nikolai.zujev@gmail.com>
*/
class FlashExtension extends \Twig_Extension
{
/**
* @var string
*/
protected $closeable;

/**
* @var array
*/
Expand All @@ -29,10 +32,12 @@ class FlashExtension extends \Twig_Extension
* Constructor.
*
* @param array $mapping
* @param string $closeable
*/
public function __construct(array $mapping)
public function __construct(array $mapping, $closeable)
{
$this->mapping = $mapping;
$this->closeable = $closeable;
}

/**
Expand All @@ -42,9 +47,18 @@ public function getFunctions()
{
return array(
new \Twig_SimpleFunction('mopa_bootstrap_flash_mapping', array($this, 'getMapping'), array('is_safe' => array('html'))),
new \Twig_SimpleFunction('mopa_bootstrap_flash_closeable', array($this, 'getCloseable')),
);
}

public function getCloseable($close = null)
{
if ($close === null) {
return $this->closeable;
}
return $close;
}

/**
* Get flash mapping.
*
Expand Down