Skip to content

Instantly share code, notes, and snippets.

@dsofeir
Created March 20, 2021 22:41
Show Gist options
  • Save dsofeir/8535155749ddf9ba6560181d36d65fe9 to your computer and use it in GitHub Desktop.
Save dsofeir/8535155749ddf9ba6560181d36d65fe9 to your computer and use it in GitHub Desktop.
Grav plugin
<?php
namespace Grav\Plugin;
use Composer\Autoload\ClassLoader;
use Grav\Common\Plugin;
use RocketTheme\Toolbox\Event\Event;
/**
* Class NotesPlugin
* @package Grav\Plugin
*/
class NotesPlugin extends Plugin
{
/**
* @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]
],
'onGetPageBlueprints' => ['onGetPageBlueprints', 0]
];
}
/**
* Composer autoload.
*is
* @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 onGetPageBlueprints($event)
{
$event_types = $event->types;
$event_types->scanBlueprints('plugin://' . $this->name . '/blueprints');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment