diff --git a/CHANGELOG.md b/CHANGELOG.md index 7022af6..2c92a63 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,10 @@ # v1.2.x -## 08/xx/2016 +## 09/xx/2016 1. [](#improved) * Added Croatian translation +1. [](#bugfix) + * Fix [#35](https://github.com/getgrav/grav-plugin-comments/issues/35) Allow comments to work fine on Form 2.0 too # v1.2.2 ## 08/12/2016 diff --git a/comments.php b/comments.php index f8ae6f4..0058eff 100644 --- a/comments.php +++ b/comments.php @@ -31,6 +31,10 @@ class CommentsPlugin extends Plugin /** * Initialize form if the page has one. Also catches form processing if user posts the form. + * + * Used by Form plugin < 2.0, kept for backwards compatibility + * + * @deprecated */ public function onPageInitialized() { @@ -49,8 +53,26 @@ class CommentsPlugin extends Plugin } } + /** + * Add the comment form information to the page header dynamically + * + * Used by Form plugin >= 2.0 + */ + public function onFormPageHeaderProcessed(Event $event) + { + $header = $event['header']; + + if ($this->enable) { + if (!isset($header->form)) { + $header->form = $this->grav['config']->get('plugins.comments.form'); + } + } + + $event->header = $header; + } + public function onTwigSiteVariables() { - $this->grav['twig']->enable = $this->enable; + $this->grav['twig']->enable_comments_plugin = $this->enable; $this->grav['twig']->comments = $this->fetchComments(); } @@ -97,6 +119,7 @@ class CommentsPlugin extends Plugin $this->enable([ 'onTwigTemplatePaths' => ['onTwigTemplatePaths', 0], 'onFormProcessed' => ['onFormProcessed', 0], + 'onFormPageHeaderProcessed' => ['onFormPageHeaderProcessed', 0], 'onPageInitialized' => ['onPageInitialized', 10], 'onTwigSiteVariables' => ['onTwigSiteVariables', 0] ]); @@ -406,4 +429,4 @@ class CommentsPlugin extends Plugin { $this->grav['admin']->dataTypesExcludedFromDataManagerPlugin[] = 'comments'; } -} +} \ No newline at end of file diff --git a/templates/partials/comments.html.twig b/templates/partials/comments.html.twig index d4d4493..6872180 100644 --- a/templates/partials/comments.html.twig +++ b/templates/partials/comments.html.twig @@ -1,4 +1,4 @@ -{% if grav.twig.enable %} +{% if grav.twig.enable_comments_plugin %}

{{'PLUGIN_COMMENTS.ADD_COMMENT'|t}}

@@ -19,7 +19,7 @@ {% else %}
{% include "forms/fields/#{field.type}/#{field.type}.html.twig" %} -
+ {% endif %} {% else %}
@@ -27,6 +27,7 @@
{% endif %} {% endfor %} + {% include "forms/fields/formname/formname.html.twig" %}
{% for button in grav.config.plugins.comments.form.buttons %}