This repository has been archived on 2021-01-24. You can view files and clone it, but cannot push or open issues or pull requests.
grav-plugin-eucookiepolicy/eucookiepolicy.php
2016-06-10 15:03:45 +02:00

54 lines
1.6 KiB
PHP
Executable File

<?php
namespace Grav\Plugin;
use Grav\Common\Plugin;
class EuCookiePolicyPlugin extends Plugin
{
public static function getSubscribedEvents() {
return [
'onPluginsInitialized' => ['onPluginsInitialized', 0],
];
}
public function onPluginsInitialized()
{
if ($this->isAdmin()) {
$this->active = false;
return;
}
$this->enable([
'onTwigTemplatePaths' => ['onTwigTemplatePaths', 0],
'onTwigSiteVariables' => ['onTwigSiteVariables', 0],
]);
}
/**
* Add current directory to twig lookup paths.
*/
public function onTwigTemplatePaths()
{
$this->grav['twig']->twig_paths[] = __DIR__ . '/templates';
}
/**
* if enabled on this page, load the JS + CSS theme.
*/
public function onTwigSiteVariables()
{
$type = strtolower($this->config->get('plugins.eucookiepolicy.type'));
$this->grav['assets']->addJs('plugin://eucookiepolicy/assets/js/cookiechoices.js');
$this->grav['assets']->addCss('plugin://eucookiepolicy/assets/css/cookiechoices.css', -999);
$twig = $this->grav['twig'];
$twig->twig_vars['eucookiepolicy_cookie_type'] = $type;
$twig->twig_vars['eucookiepolicy_url'] = $this->config->get('plugins.eucookiepolicy.url');
$twig->twig_vars['eucookiepolicy_markup'] = $twig->twig->render('partials/eucookiepolicy.html.twig', array(
'eucookiepolicy_cookie_type' => $twig->twig_vars['eucookiepolicy_cookie_type'],
'eucookiepolicy_url' => $twig->twig_vars['eucookiepolicy_url']
));
}
}