Skip to content

Commit

Permalink
some debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
rhukster committed Jun 27, 2023
1 parent b7128d8 commit ef1da19
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# v7.2.1
## mm/dd/2023

1. [](#improved)
* Added some optional debug output to help isolate form loading problems
1. [](#bugfix)
* More robust fix for multi-language form caching

Expand Down
11 changes: 11 additions & 0 deletions blueprints.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@ form:
title: PLUGIN_FORM.GENERAL

fields:
debug:
type: toggle
label: Debug
highlight: 1
default: 0
options:
1: PLUGIN_ADMIN.ENABLED
0: PLUGIN_ADMIN.DISABLED
validate:
type: bool

built_in_css:
type: toggle
label: PLUGIN_FORM.USE_BUILT_IN_CSS
Expand Down
33 changes: 31 additions & 2 deletions form.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use Grav\Plugin\Form\Forms;
use Grav\Plugin\Form\TwigExtension;
use Grav\Common\HTTP\Client;
use Monolog\Logger;
use ReCaptcha\ReCaptcha;
use ReCaptcha\RequestMethod\CurlPost;
use RecursiveArrayIterator;
Expand Down Expand Up @@ -148,6 +149,8 @@ class_alias(Form::class, 'Grav\Plugin\Form');
'onTwigSiteVariables' => ['onTwigVariables', 0],
'onFormValidationProcessed' => ['onFormValidationProcessed', 0],
]);


}

/**
Expand Down Expand Up @@ -225,6 +228,7 @@ public function onPageInitialized(): void
/** @var PageInterface $page */
$page = $this->grav['page'];


// Force rebuild form when form has not been built and form cache expired.
// This happens when form cache expires before the page cache
// and then does not trigger 'onPageProcessed' event.
Expand Down Expand Up @@ -1258,6 +1262,12 @@ protected function loadCachedForms(): void
// Only update the forms if it's not empty
if ($forms) {
$this->forms = array_merge($this->forms, $forms);
if ($this->config()['debug']) {
/** @var Logger $logger */
$logger = $this->grav['log'];
$logger->addDebug(sprintf("<<<< Loaded cached forms: %s\n%s", $this->getFormCacheId(), $this->arrayToString($this->forms)));
}

}
}

Expand All @@ -1272,8 +1282,11 @@ protected function saveCachedForms(): void
$cache = $this->grav['cache'];
$cache_id = $this->getFormCacheId();
$cache->save($cache_id, [$this->forms]);
// $this->grav['debugger']->addMessage("cache_id: {$cache_id}");
// $this->grav['debugger']->addMessage($this->forms);
if ($this->config()['debug']) {
/** @var Logger $logger */
$logger = $this->grav['log'];
$logger->addDebug(sprintf(">>>> Saved cached forms: %s\n%s", $this->getFormCacheId(), $this->arrayToString($this->forms)));
}
}

/**
Expand Down Expand Up @@ -1319,4 +1332,20 @@ protected function processBasicCaptchaImage(Uri $uri)
exit;
}
}

protected function arrayToString($array, $level = 0) {
$result = '';

foreach ($array as $key => $value) {
if (is_array($value)) {
if ($level < 2) {
$result .= "$key: " . $this->arrayToString($value, $level + 1) . "\n";
}
} else {
$result .= "$key: $value\n";
}
}

return $result;
}
}
1 change: 1 addition & 0 deletions form.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ built_in_css: true
inline_css: true
refresh_prevention: false
client_side_validation: true
debug: false
inline_errors: false
files:
multiple: false # To allow multiple files, default is single
Expand Down

0 comments on commit ef1da19

Please sign in to comment.