Fix order of events preventing new comment from appearing immediately

This commit is contained in:
Flavio Copes 2015-10-15 15:43:45 +02:00
parent f064eb3bbb
commit fe66c4bfd6
1 changed files with 19 additions and 10 deletions

View File

@ -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 */