From fe66c4bfd60c4011d8f80ac0d91402262147ca50 Mon Sep 17 00:00:00 2001 From: Flavio Copes Date: Thu, 15 Oct 2015 15:43:45 +0200 Subject: [PATCH] Fix order of events preventing new comment from appearing immediately --- comments.php | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/comments.php b/comments.php index 3396bd9..9570777 100644 --- a/comments.php +++ b/comments.php @@ -25,6 +25,7 @@ class CommentsPlugin extends Plugin 'onPluginsInitialized' => ['onPluginsInitialized', 0], 'onFormProcessed' => ['onFormProcessed', 0], 'onPageInitialized' => ['onPageInitialized', 0], + 'onTwigSiteVariables' => ['onTwigSiteVariables', 0] ]; } @@ -33,15 +34,25 @@ class CommentsPlugin extends Plugin */ public function onPageInitialized() { - /** @var Page $page */ - $page = $this->grav['page']; - if (!$page) { - return; - } + if (!$this->isAdmin()) { + /** @var Page $page */ + $page = $this->grav['page']; + if (!$page) { + return; + } - $header = $page->header(); - $header->form = $this->grav['config']->get('plugins.comments.form'); - $page->header($header); + $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 */