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