taxonomylist.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. namespace Grav\Plugin;
  3. use Composer\Autoload\ClassLoader;
  4. use Grav\Common\Plugin;
  5. class TaxonomylistPlugin extends Plugin
  6. {
  7. /**
  8. * @return array
  9. */
  10. public static function getSubscribedEvents(): array
  11. {
  12. return [
  13. 'onPluginsInitialized' => [
  14. ['autoload', 100000],
  15. ['onPluginsInitialized', 0]
  16. ]
  17. ];
  18. }
  19. /**
  20. * [PluginsLoadedEvent:100000] Composer autoload.
  21. *
  22. * @return ClassLoader
  23. */
  24. public function autoload(): ClassLoader
  25. {
  26. return require __DIR__ . '/vendor/autoload.php';
  27. }
  28. /**
  29. * Initialize configuration
  30. *
  31. * @return void
  32. */
  33. public function onPluginsInitialized()
  34. {
  35. if ($this->isAdmin()) {
  36. $this->active = false;
  37. return;
  38. }
  39. $this->enable([
  40. 'onTwigTemplatePaths' => ['onTwigTemplatePaths', 0],
  41. 'onTwigSiteVariables' => ['onTwigSiteVariables', 0]
  42. ]);
  43. }
  44. /**
  45. * Add current directory to twig lookup paths.
  46. *
  47. * @return void
  48. */
  49. public function onTwigTemplatePaths()
  50. {
  51. $this->grav['twig']->twig_paths[] = __DIR__ . '/templates';
  52. }
  53. /**
  54. * Set needed variables to display the taxonomy list.
  55. *
  56. * @return void
  57. */
  58. public function onTwigSiteVariables()
  59. {
  60. $twig = $this->grav['twig'];
  61. $twig->twig_vars['taxonomylist'] = new Taxonomylist();
  62. $twig->twig_vars['list_url'] = $this->config->get(
  63. 'site.blog.route',
  64. $this->config->get('plugins.taxonomylist.route')
  65. );
  66. }
  67. }