Skip to content

Commit

Permalink
Allow to hide/show different btn (deny, allow)
Browse files Browse the repository at this point in the history
  • Loading branch information
devcut committed Apr 23, 2021
1 parent 2dafce9 commit 7294a19
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 25 deletions.
9 changes: 9 additions & 0 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ public function getConfigTreeBuilder()
->children()
->scalarNode('redirection_url')->defaultValue('fluffy_gdpr')->end()
->end()
->children()
->arrayNode('btn')
->addDefaultsIfNotSet()
->children()
->booleanNode('deny')->defaultValue(true)->end()
->booleanNode('accept')->defaultValue(true)->end()
->end()
->end()
->end()
->children()
->arrayNode('design')
->addDefaultsIfNotSet()
Expand Down
1 change: 1 addition & 0 deletions DependencyInjection/GdprExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public function load(array $configs, ContainerBuilder $container)

$container->setParameter('fluffy.gdpr.redirection_url', $config['redirection_url']);
$container->setParameter('fluffy.gdpr.design', $config['design']);
$container->setParameter('fluffy.gdpr.btn', $config['btn']);
$container->setParameter('fluffy.gdpr.cookies', $config);
}
}
42 changes: 24 additions & 18 deletions Resources/views/cookie_bar.html.twig
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div id="js-ff-cookie-bar" class="ff-cookie_bar"
{% if not getDesign('disable') %}
style="background-color: {{ getDesign('bg_color') }}; color: {{ getDesign('text_color') }}"
{% endif %}
{% if not getDesign('disable') %}
style="background-color: {{ getDesign('bg_color') }}; color: {{ getDesign('text_color') }}"
{% endif %}
>
{# Header #}
<div class="ff-cookie_bar_header">
Expand All @@ -20,20 +20,26 @@
</div>

{# Footer #}
<div class="ff-cookie_bar_footer">
<a href="" id="js-ff-cookies-deny" class="ff-cookie_bar_btn deny"
{% if not getDesign('disable') %}
style="background-color: {{ getDesign('btn_deny_bg_color') }}; color: {{ getDesign('btn_deny_text_color') }}"
{% if showBtn('deny') or showBtn('accept') %}
<div class="ff-cookie_bar_footer">
{% if showBtn('deny') %}
<a href="" id="js-ff-cookies-deny" class="ff-cookie_bar_btn deny"
{% if not getDesign('disable') %}
style="background-color: {{ getDesign('btn_deny_bg_color') }}; color: {{ getDesign('btn_deny_text_color') }}"
{% endif %}
>
{{ 'cookies_bar.deny'|trans({},'GdprBundle') }}
</a>
{% endif %}
>
{{ 'cookies_bar.deny'|trans({},'GdprBundle') }}
</a>
<a href="" id="js-ff-cookies-allow" class="ff-cookie_bar_btn allow"
{% if not getDesign('disable') %}
style="background-color: {{ getDesign('btn_allow_bg_color') }}; color: {{ getDesign('btn_allow_text_color') }}"
{% if showBtn('accept') %}
<a href="" id="js-ff-cookies-allow" class="ff-cookie_bar_btn allow"
{% if not getDesign('disable') %}
style="background-color: {{ getDesign('btn_allow_bg_color') }}; color: {{ getDesign('btn_allow_text_color') }}"
{% endif %}
>
{{ 'cookies.accept'|trans({},'GdprBundle') }}
</a>
{% endif %}
>
{{ 'cookies.accept'|trans({},'GdprBundle') }}
</a>
</div>
</div>
</div>
{% endif %}
</div>
5 changes: 3 additions & 2 deletions Service/CookieService.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@

namespace FluffyFactory\Bundle\GdprBundle\Service;


use FluffyFactory\Bundle\GdprBundle\Model\Cookie;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\HttpFoundation\RequestStack;

class CookieService
{

/**
* @var array
*/
Expand Down Expand Up @@ -99,6 +97,9 @@ public function getOptionnalCookies(): array
return $this->filterCookies(false);
}

/**
* @return string
*/
public function getRedirectionUrl(): string
{
return $this->params->get('fluffy.gdpr.redirection_url');
Expand Down
19 changes: 15 additions & 4 deletions Twig/cookieBarExtension.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
<?php


namespace FluffyFactory\Bundle\GdprBundle\Twig;


use FluffyFactory\Bundle\GdprBundle\Service\CookieService;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;

class cookieBarExtension extends AbstractExtension
{

/**
* @var CookieService
*/
Expand All @@ -33,6 +30,7 @@ public function getFunctions()
new TwigFunction('showCookieBar', [$this, 'showCookieBar']),
new TwigFunction('getOptionnalCookiesNames', [$this, 'getOptionnalCookiesNames'], ['is_safe' => ['html']]),
new TwigFunction('getDesign', [$this, 'getDesign']),
new TwigFunction('showBtn', [$this, 'showBtn']),
new TwigFunction('allowedCookie', [$this, 'allowedCookie']),
];
}
Expand Down Expand Up @@ -68,7 +66,20 @@ public function getDesign(string $key): string
return $this->params->get('fluffy.gdpr.design')[$key];
}

public function allowedCookie(string $cookieName)
/**
* @param string $key
* @return bool
*/
public function showBtn(string $key): bool
{
return $this->params->get('fluffy.gdpr.btn')[$key];
}

/**
* @param string $cookieName
* @return bool
*/
public function allowedCookie(string $cookieName): bool
{
return $this->cookieService->getUserCookie($cookieName) === "1";
}
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
}
],
"require": {
"php": ">=7.2.0"
"php": ">=7.2.0",
"ext-json": "*"
},
"autoload": {
"psr-4": {
Expand Down

0 comments on commit 7294a19

Please sign in to comment.