No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

breadcrumbs.php 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. namespace Grav\Plugin;
  3. use \Grav\Common\Plugin;
  4. class BreadcrumbsPlugin extends Plugin
  5. {
  6. /**
  7. * @return array
  8. */
  9. public static function getSubscribedEvents()
  10. {
  11. return [
  12. 'onPluginsInitialized' => ['onPluginsInitialized', 0]
  13. ];
  14. }
  15. /**
  16. * Initialize configuration
  17. */
  18. public function onPluginsInitialized()
  19. {
  20. if ($this->isAdmin()) {
  21. $this->active = false;
  22. return;
  23. }
  24. $this->enable([
  25. 'onTwigTemplatePaths' => ['onTwigTemplatePaths', 0],
  26. 'onTwigSiteVariables' => ['onTwigSiteVariables', 0]
  27. ]);
  28. }
  29. /**
  30. * Add current directory to twig lookup paths.
  31. */
  32. public function onTwigTemplatePaths()
  33. {
  34. $this->grav['twig']->twig_paths[] = __DIR__ . '/templates';
  35. }
  36. /**
  37. * Set needed variables to display breadcrumbs.
  38. */
  39. public function onTwigSiteVariables()
  40. {
  41. require_once __DIR__ . '/classes/breadcrumbs.php';
  42. $this->grav['twig']->twig_vars['breadcrumbs'] = new Breadcrumbs($this->config->get('plugins.breadcrumbs'));
  43. if ($this->config->get('plugins.breadcrumbs.built_in_css')) {
  44. $this->grav['assets']->add('plugin://breadcrumbs/css/breadcrumbs.css');
  45. }
  46. }
  47. }