Fix order of events preventing new comment from appearing immediately
This commit is contained in:
parent
f064eb3bbb
commit
fe66c4bfd6
29
comments.php
29
comments.php
|
@ -25,6 +25,7 @@ class CommentsPlugin extends Plugin
|
||||||
'onPluginsInitialized' => ['onPluginsInitialized', 0],
|
'onPluginsInitialized' => ['onPluginsInitialized', 0],
|
||||||
'onFormProcessed' => ['onFormProcessed', 0],
|
'onFormProcessed' => ['onFormProcessed', 0],
|
||||||
'onPageInitialized' => ['onPageInitialized', 0],
|
'onPageInitialized' => ['onPageInitialized', 0],
|
||||||
|
'onTwigSiteVariables' => ['onTwigSiteVariables', 0]
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,15 +34,25 @@ class CommentsPlugin extends Plugin
|
||||||
*/
|
*/
|
||||||
public function onPageInitialized()
|
public function onPageInitialized()
|
||||||
{
|
{
|
||||||
/** @var Page $page */
|
if (!$this->isAdmin()) {
|
||||||
$page = $this->grav['page'];
|
/** @var Page $page */
|
||||||
if (!$page) {
|
$page = $this->grav['page'];
|
||||||
return;
|
if (!$page) {
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$header = $page->header();
|
$header = $page->header();
|
||||||
$header->form = $this->grav['config']->get('plugins.comments.form');
|
if (!isset($header->form)) {
|
||||||
$page->header($header);
|
$header->form = $this->grav['config']->get('plugins.comments.form');
|
||||||
|
$page->header($header);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onTwigSiteVariables() {
|
||||||
|
if (!$this->isAdmin()) {
|
||||||
|
$this->grav['twig']->comments = $this->fetchComments();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -54,8 +65,6 @@ class CommentsPlugin extends Plugin
|
||||||
'onTwigTemplatePaths' => ['onTwigTemplatePaths', 0],
|
'onTwigTemplatePaths' => ['onTwigTemplatePaths', 0],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->grav['twig']->comments = $this->fetchComments();
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
/** @var Uri $uri */
|
/** @var Uri $uri */
|
||||||
|
|
Loading…
Reference in New Issue