-
Notifications
You must be signed in to change notification settings - Fork 5
/
cascade-filters.php
58 lines (51 loc) · 1.46 KB
/
cascade-filters.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
namespace Grav\Plugin;
use Grav\Common\Plugin;
use RocketTheme\Toolbox\Event\Event;
/**
* Class CascadeFiltersPlugin
* @package Grav\Plugin
*/
class CascadeFiltersPlugin extends Plugin
{
public static function getSubscribedEvents()
{
return [
'onPluginsInitialized' => ['onPluginsInitialized', 0]
];
}
public function onPluginsInitialized() {
if ($this->isAdmin()) {
$this->active = false;
return;
}
$this->selected_pages = $this->config->get( 'plugins.' . $this->name . '.select_pages' );
$this->enable([
'onPageInitialized' => [ 'onPageInitialized', 0 ],
'onTwigTemplatePaths' => ['onTwigTemplatePaths', 0],
] );
}
public function onPageInitialized() {
if (! in_array($this->grav['page']->rawRoute(), $this->selected_pages)) {
return;
}
$this->enable([
'onTwigSiteVariables' => ['onTwigSiteVariables', 0]
]);
}
/**
* Add current directory to twig lookup paths.
*/
public function onTwigTemplatePaths() {
$this->grav['twig']->twig_paths[] = __DIR__ . '/templates';
}
/**
* Set needed variables to display the taxonomy list.
*/
public function onTwigSiteVariables() {
require_once __DIR__ . '/classes/cascade-filters.php';
$twig = $this->grav['twig'];
$filters = $this->config->get( 'plugins.' . $this->name . '.taxonomy_filters' );
$twig->twig_vars['cascadeFilters'] = new CascadeFilters($filters);
}
}