diff --git a/CHANGELOG.md b/CHANGELOG.md index bdd64b23..47691f1e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ +# v2.1.0 +## xx/xx/2017 + +1. [](#improved) + * Reworked logic so form caching is based on `Pages::getPagesCacheId()` +1. [](#bugfix) + * Fixed issue with `honeypot` field not throwing exception properly + # v2.0.10 ## 02/08/2017 diff --git a/form.php b/form.php index 7a0cfffa..d46e0466 100644 --- a/form.php +++ b/form.php @@ -22,11 +22,6 @@ class FormPlugin extends Plugin 'blueprints' => 1000 ]; - /** - * @var bool - */ - protected $active = false; - /** * @var Form */ @@ -38,8 +33,6 @@ class FormPlugin extends Plugin protected $json_response = []; - protected $cache_id = 'plugin-form'; - protected $recache_forms = false; @@ -61,6 +54,8 @@ public function onPluginsInitialized() { require_once(__DIR__ . '/classes/form.php'); + + if ($this->isAdmin()) { $this->enable([ 'onPagesInitialized' => ['onPagesInitialized', 0] @@ -74,19 +69,6 @@ public function onPluginsInitialized() 'onTwigInitialized' => ['onTwigInitialized', 0], 'onFormValidationProcessed' => ['onFormValidationProcessed', 0], ]); - - // Get and set the cache of forms if it exists - list($forms, $flat_forms) = $this->grav['cache']->fetch($this->cache_id); - - // Only store the forms if they are an array - if (is_array($forms)) { - $this->forms = $forms; - } - - // Only store the flat_forms if they are an array - if (is_array($flat_forms)) { - $this->flat_forms = $flat_forms; - } } /** @@ -144,6 +126,21 @@ public function onPagesInitialized() { $submitted = false; + $cache_id = $this->grav['pages']->getPagesCacheId() . '-form-plugin'; + + // Get and set the cache of forms if it exists + list($forms, $flat_forms) = $this->grav['cache']->fetch($cache_id); + + // Only store the forms if they are an array + if (is_array($forms)) { + $this->forms = $forms; + } + + // Only store the flat_forms if they are an array + if (is_array($flat_forms)) { + $this->flat_forms = $flat_forms; + } + if ($this->isAdmin() && !empty($_POST)) { $page = $this->grav['page']; @@ -154,7 +151,6 @@ public function onPagesInitialized() $header = $page->header(); if (isset($header->form) && is_array($header->form)) { - $this->active = true; // Create form $this->form = new Form($page); $this->enable([ @@ -179,11 +175,9 @@ public function onPagesInitialized() // Save the current state of the forms to cache if ($this->recache_forms) { - $this->grav['cache']->save($this->cache_id, [$this->forms, $this->flat_forms]); + $this->grav['cache']->save($cache_id, [$this->forms, $this->flat_forms]); } - $this->active = true; - // Handle posting if needed. if (!empty($_POST)) { @@ -253,10 +247,6 @@ public function onTwigTemplatePaths() */ public function onTwigVariables(Event $event = null) { - if (!$this->active) { - return; - } - if ($event && isset($event['page'])) { $page = $event['page']; } else {