From 3d25ad7de4fdbb3eba2cde2a62422e6be5d79a0a Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Tue, 25 Aug 2026 22:57:22 +0000
Subject: [PATCH] =It's been a minute. I went through the Routes and associated Managers and ensured they played together well. Reworked the Cache.php, and I think I caught all the references. Moving away from JVBase() root class, to individuall classes that are Instanced. Double checked for the ABSPATH check in every file, and added index.php to every directory that didn't already have it. Also still working on the MenuBlock to work with WooCommerce for now for Northeh
---
inc/blocks/FormBlock.php | 67 +++++++++++++++------------------
1 files changed, 30 insertions(+), 37 deletions(-)
diff --git a/inc/blocks/FormBlock.php b/inc/blocks/FormBlock.php
index 512a9c9..5cd1b22 100644
--- a/inc/blocks/FormBlock.php
+++ b/inc/blocks/FormBlock.php
@@ -1,12 +1,10 @@
<?php
namespace JVBase\blocks;
-use JVBase\managers\CacheManager;
-use JVBase\meta\MetaManager;
-use JVBase\managers\CloudflareTurnstile;
-use Exception;
-use JVBase\utility\Features;
-use WP_Block;
+use JVBase\integrations\services\Cloudflare;
+use JVBase\managers\Cache;
+use JVBase\meta\Form;
+use JVBase\base\Site;
if (!defined('ABSPATH')) {
exit; // Exit if accessed directly
@@ -19,8 +17,8 @@
*/
class FormBlock
{
- protected static FormBlock|null $instance = null;
- protected CacheManager $cache;
+ protected static ?FormBlock $instance = null;
+ protected Cache $cache;
protected array $forms;
protected string $form_contact;
@@ -36,7 +34,11 @@
public function __construct()
{
- $this->cache = CacheManager::for('form_blocks', WEEK_IN_SECONDS);
+ $this->cache = Cache::for('forms', null, WEEK_IN_SECONDS);
+
+ if (JVB_TESTING) {
+ $this->cache->flush();
+ }
// Initialize forms from filter
$this->forms = $this->registerForms();
$this->form_contact = apply_filters('jvb_form_contact', '');
@@ -61,8 +63,8 @@
}
// Enqueue Turnstile if needed
- if (Features::forSite()->hasIntegration('cloudflare')) {
- $cloudflare = JVB()->connect('cloudflare');
+ if (Site::hasIntegration('cloudflare')) {
+ $cloudflare = Cloudflare::getInstance();
if ($cloudflare->isSetUp()) {
$cloudflare->enqueueTurnstileScripts();
}
@@ -130,17 +132,12 @@
return '<div class="jvb-form-error">No valid form type selected. Please edit this block and select a form type.</div>';
}
- $cache_key = $this->cache->generateKey($block);
- $cached = $this->cache->get($cache_key);
- $cached = false;
- if ($cached) {
- return $cached;
- }
-
- $rendered = $this->renderForm($form_type, $block);
-
- $this->cache->set($cache_key, $rendered);
- return $rendered;
+ return $this->cache->remember(
+ $block,
+ function() use ($form_type, $block) {
+ return $this->renderForm($form_type, $block);
+ }
+ );
}
/**
@@ -185,7 +182,6 @@
$this->renderTurnstile();
$this->renderFormEnd($type, $form_id);
echo '</div>';
-
return ob_get_clean();
}
@@ -283,7 +279,7 @@
}
}
- echo '<form id="' . esc_attr($form_id) . '" data-form-id="'.esc_attr($type).'" data-save="form" data-noautosave>';
+ echo '<form id="' . esc_attr($form_id) . '" data-form-id="'.esc_attr($type).'" data-save="form" data-handled data-step>';
// wp_nonce_field('jvb_form_' . $type);
}
@@ -298,17 +294,14 @@
return;
}
- // Create MetaManager instance for form rendering
- $meta = new MetaManager();
-
// If sections are defined, render in sections
if (!empty($form_config['sections'])) {
- $this->renderSections($type, $meta);
+ $this->renderSections($type);
} else {
echo jvbFormStatus();
// Render fields directly
foreach ($form_config['fields'] as $field_name => $field_config) {
- $meta->render('form', $field_name, $field_config);
+ echo Form::render($field_name, null, $field_config);
}
$submit_text = $form_config['submit'] ?? 'Submit';
echo '<button type="submit" class="button primary">' . esc_html($submit_text) . '</button>';
@@ -318,7 +311,7 @@
/**
* Render form sections
*/
- protected function renderSections(string $type, MetaManager $meta): void
+ protected function renderSections(string $type): void
{
$form_config = $this->forms[$type];
$sections = $form_config['sections'];
@@ -328,13 +321,13 @@
echo '<div class="container">';
if ($total > 1) {
echo '<div class="form-progress">';
- jvbRenderProgressBar('<span class="step-text">Step <span class="current">1</span> of ' . $total . '</span>');
+ jvbRenderProgressBar('<span class="step-text">Step <span class="current">1</span> of ' . $total . '</span>', false, false);
echo '</div>';
}
// Render navigation if multiple sections
if (count($sections) > 1) {
- echo '<nav class="tabs row start" role="tablist">';
+ echo '<nav class="tabs row left" role="tablist">';
$i = 1;
foreach ($sections as $slug => $section) {
$active_class = $i === 1 ? ' active' : '';
@@ -342,7 +335,7 @@
echo '<button type="button" class="tab' . $active_class . '" data-tab="' . esc_attr($slug) . '" data-step="'.$i.'" role="tab" aria-selected="' . $aria_selected . '">';
echo '<span class="step-number">' . $i . '</span>';
- echo '<h2>' . esc_html($section['label'] ?? $section) . '</h2>';
+ echo '<span>' . esc_html($section['label'] ?? $section) . '</span>';
echo '</button>';
$i++;
}
@@ -373,11 +366,11 @@
});
foreach ($section_fields as $field_name => $field_config) {
- $meta->render('form', $field_name, $field_config);
+ echo Form::render($field_name, null, $field_config);
}
// Add step navigation buttons
- echo '<div class="step-navigation row btw">';
+ echo '<div class="step-navigation row x-btw">';
if ($i > 0) {
echo '<button type="button" class="button secondary prev-step" data-action="prev-step">';
@@ -412,11 +405,11 @@
*/
protected function renderTurnstile(): void
{
- if (!Features::hasIntegration('cloudflare')) {
+ if (!Site::hasIntegration('cloudflare')) {
return;
}
- $cloudflare = JVB()->connect('cloudflare');
+ $cloudflare = Cloudflare::getInstance();
if ($cloudflare->isSetUp()) {
$cloudflare->renderTurnstile();
}
--
Gitblit v1.10.0