12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- <?php
- namespace Grav\Plugin;
- use Composer\Autoload\ClassLoader;
- use Grav\Common\Plugin;
- use Grav\Events\FlexRegisterEvent;
- /**
- * Class {{ component.name|camelize }}Plugin
- * @package Grav\Plugin
- */
- class {{ component.name|camelize }}Plugin extends Plugin
- {
- public $features = [
- 'blueprints' => 0,
- ];
- /**
- * @return array
- *
- * The getSubscribedEvents() gives the core a list of events
- * that the plugin wants to listen to. The key of each
- * array section is the event that the plugin listens to
- * and the value (in the form of an array) contains the
- * callable (or function) as well as the priority. The
- * higher the number the higher the priority.
- */
- public static function getSubscribedEvents(): array
- {
- return [
- 'onPluginsInitialized' => [
- // Uncomment following line when plugin requires Grav < 1.7
- // ['autoload', 100000],
- ['onPluginsInitialized', 0]
- ],
- FlexRegisterEvent::class => [['onRegisterFlex', 0]],
- ];
- }
- /**
- * Composer autoload
- *
- * @return ClassLoader
- */
- public function autoload(): ClassLoader
- {
- return require __DIR__ . '/vendor/autoload.php';
- }
- /**
- * Initialize the plugin
- */
- public function onPluginsInitialized(): void
- {
- // Don't proceed if we are in the admin plugin
- if ($this->isAdmin()) {
- return;
- }
- // Enable the main events we are interested in
- $this->enable([
- // Put your main events here
- ]);
- }
- public function onRegisterFlex($event): void
- {
- $flex = $event->flex;
- $flex->addDirectoryType(
- '{{ component.flex_name|lower|underscorize }}',
- 'blueprints://flex-objects/{{ component.flex_name|lower|underscorize }}.yaml'
- );
- }
- }
|