70 lines
1.7 KiB
PHP
70 lines
1.7 KiB
PHP
<?php
|
|
namespace Grav\Plugin;
|
|
|
|
use Grav\Common\GPM\GPM;
|
|
use Grav\Common\Grav;
|
|
use Grav\Common\Page\Page;
|
|
use Grav\Common\Page\Pages;
|
|
use Grav\Common\Plugin;
|
|
|
|
class CommentsPlugin extends Plugin
|
|
{
|
|
protected $route = 'comments';
|
|
|
|
/**
|
|
* @return array
|
|
*/
|
|
public static function getSubscribedEvents()
|
|
{
|
|
return [
|
|
'onPluginsInitialized' => ['onPluginsInitialized', 0],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Enable search only if url matches to the configuration.
|
|
*/
|
|
public function onPluginsInitialized()
|
|
{
|
|
if (!$this->isAdmin()) {
|
|
return;
|
|
}
|
|
|
|
$this->enable([
|
|
'onTwigTemplatePaths' => ['onTwigTemplatePaths', 0],
|
|
'onAdminTemplateNavPluginHook' => ['onAdminTemplateNavPluginHook', 0],
|
|
'onDataTypeExcludeFromDataManagerPluginHook' => ['onDataTypeExcludeFromDataManagerPluginHook', 0],
|
|
]);
|
|
|
|
$comments[] = [
|
|
'route' => 'comment-test-1',
|
|
'content' => 'A comment text'
|
|
];
|
|
|
|
$this->grav['twig']->comments = $comments;
|
|
}
|
|
|
|
/**
|
|
* Add plugin templates path
|
|
*/
|
|
public function onTwigTemplatePaths()
|
|
{
|
|
$this->grav['twig']->twig_paths[] = __DIR__ . '/admin/templates';
|
|
}
|
|
|
|
/**
|
|
* Add navigation item to the admin plugin
|
|
*/
|
|
public function onAdminTemplateNavPluginHook()
|
|
{
|
|
$this->grav['twig']->plugins_hooked_nav['PLUGIN_COMMENTS.COMMENTS'] = ['route' => $this->route, 'icon' => 'fa-file-text'];
|
|
}
|
|
|
|
/**
|
|
* Exclude comments from the Data Manager plugin
|
|
*/
|
|
public function onDataTypeExcludeFromDataManagerPluginHook()
|
|
{
|
|
$this->grav['admin']->dataTypesExcludedFromDataManagerPlugin[] = 'comments';
|
|
}
|
|
}
|