Skip to content
This repository has been archived by the owner on Jun 20, 2023. It is now read-only.

Commit

Permalink
fixed some todo markers, refs #55
Browse files Browse the repository at this point in the history
  • Loading branch information
Guite committed Oct 21, 2016
1 parent 27c1935 commit 0569fef
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Controller/ConfigController.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function configAction(Request $request)

];
// get all user groups
// TODO legacy call
// @todo legacy call
$groups = ModUtil::apiFunc('ZikulaGroupsModule', 'user', 'getall');
foreach ($groups as $group) {
$groupChoices[$group['name']] = $group['gid'];
Expand Down
2 changes: 1 addition & 1 deletion Helper/ResetAgreementHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function reset($groupId = -1)
// single group

// get the group incl members
// TODO legacy call
// @todo legacy call
$grp = ModUtil::apiFunc('ZikulaGroupsModule', 'user', 'get', ['gid' => $groupId]);
if ($grp == false) {
return false;
Expand Down
52 changes: 39 additions & 13 deletions Listener/EuCookieWarningInjectorListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@

namespace Zikula\LegalModule\Listener;

use ModUtil;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\Translation\TranslatorInterface;
use Zikula\ExtensionsModule\Api\VariableApi;
use Zikula\LegalModule\Constant as LegalConstant;
use Zikula\ThemeModule\Engine\Asset;

/**
* EuCookieWarningInjectorListener injects a warning to the user that cookies are
Expand All @@ -30,10 +32,39 @@
*/
class EuCookieWarningInjectorListener implements EventSubscriberInterface
{
/**
* @var TranslatorInterface
*/
private $translator;

/**
* @var VariableApi
*/
private $variableApi;

/**
* @var Asset
*/
private $assetHelper;

/**
* @var string
*/
private $stylesheetOverride;

public function __construct($stylesheetOverride = null)
/**
* Constructor.
*
* @param TranslatorInterface $translator Translator service instance
* @param VariableApi $variableApi VariableApi service instance
* @param Asset $assetHelper Asset service instance
* @param string $stylesheetOverride Custom path to css file (optional)
*/
public function __construct(TranslatorInterface $translator, VariableApi $variableApi, Asset $assetHelper, $stylesheetOverride = null)
{
$this->translator = $translator;
$this->variableApi = $variableApi;
$this->assetHelper = $assetHelper;
$this->stylesheetOverride = $stylesheetOverride;
}

Expand All @@ -54,9 +85,8 @@ public function onKernelResponse(FilterResponseEvent $event)
return;
}

// is modvar enabled?
// TODO legacy call
$cookieSetting = ModUtil::getVar(LegalConstant::MODNAME, LegalConstant::MODVAR_EUCOOKIE);
// is functionality enabled?
$cookieSetting = $this->variableApi->get(LegalConstant::MODNAME, LegalConstant::MODVAR_EUCOOKIE);
if (empty($cookieSetting)) {
return;
}
Expand All @@ -83,13 +113,11 @@ protected function injectWarning(Request $request, Response $response)
// add javascript to bottom of body
$pos = strripos($content, '</body>');
if (false !== $pos) {
// TODO legacy call
$module = ModUtil::getModule(LegalConstant::MODNAME);
$path = $request->getBasePath().'/'.$module->getRelativePath().'/Resources/public/js/jquery.cookiebar/jquery.cookiebar.js';
$path = $this->assetHelper->resolve('@ZikulaLegalModule:js/jquery.cookiebar/jquery.cookiebar.js');
$javascript = '<script type="text/javascript" src="'.$path.'"></script>';
// allow translation of content
$message = __('We use cookies to track usage and preferences', $module->getTranslationDomain());
$acceptText = __('I Understand', $module->getTranslationDomain());
$message = $this->translator->__('We use cookies to track usage and preferences');
$acceptText = $this->translator->__('I Understand');
$javascript .= '
<script type="text/javascript">
jQuery(document).ready(function() {
Expand All @@ -106,12 +134,10 @@ protected function injectWarning(Request $request, Response $response)
// add stylesheet to head
$pos = strripos($content, '</head>');
if (false !== $pos) {
// TODO legacy call
$module = ModUtil::getModule(LegalConstant::MODNAME);
if (!empty($this->stylesheetOverride) && file_exists($this->stylesheetOverride)) {
$path = $this->stylesheetOverride;
} else {
$path = $request->getBasePath().'/'.$module->getRelativePath().'/Resources/public/js/jquery.cookiebar/jquery.cookiebar.css';
$path = $this->assetHelper->resolve('@ZikulaLegalModule:js/jquery.cookiebar/jquery.cookiebar.css');
}
$css = '<link rel="stylesheet" type="text/css" href="'.$path.'" />';
$content = substr($content, 0, $pos).$css.substr($content, $pos);
Expand Down
2 changes: 1 addition & 1 deletion Listener/UsersUiListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class UsersUiListener implements EventSubscriberInterface
private $validation;

/**
* Constructs a new instance of this class.
* Constructor.
*
* @param RequestStack $requestStack RequestStack service instance
* @param Twig_Environment $twig The twig templating service
Expand Down
3 changes: 3 additions & 0 deletions Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@

<service id="zikula_legal_module.eu_warning_listener" class="%zikula_legal_module.eu_warning_listener.class%">
<tag name="kernel.event_subscriber" />
<argument type="service" id="translator.default" />
<argument type="service" id="zikula_extensions_module.api.variable" />
<argument type="service" id="zikula_core.common.theme.asset_helper" />
<argument>%euwarning.stylesheet%</argument>
</service>

Expand Down

0 comments on commit 0569fef

Please sign in to comment.