From 2127b1bdd73ecd2423e443992da4b442f5a3c1a3 Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Wed, 04 Feb 2026 21:19:25 +0000
Subject: [PATCH] =Major overhaul of MetaManager.php -> Meta.php and RestRouteManager.php -> Rest.php. Seems to work for JakeVan

---
 inc/ui/CRUDSkeleton.php |  150 ++++++++++++++++++++++++++-----------------------
 1 files changed, 79 insertions(+), 71 deletions(-)

diff --git a/inc/ui/CRUDSkeleton.php b/inc/ui/CRUDSkeleton.php
index 10b30cb..380a25b 100644
--- a/inc/ui/CRUDSkeleton.php
+++ b/inc/ui/CRUDSkeleton.php
@@ -2,8 +2,7 @@
 namespace JVBase\ui;
 
 use JVBase\managers\UserTermsManager;
-use JVBase\meta\MetaForm;
-use JVBase\meta\MetaManager;
+use JVBase\meta\Form;
 use WP_User;
 
 if (!defined('ABSPATH')) {
@@ -36,7 +35,7 @@
 	protected string $dataType = '';
 	protected string $singular = '';
 	protected string $plural = '';
-	protected string $icon = 'triangle';
+	protected string $icon;
 
 	// Capabilities
 	protected array $caps = [];
@@ -121,10 +120,6 @@
 	protected $dataSourceCallback = null;
 	protected array $templates = [];
 
-	// Metadata handling
-	protected ?MetaManager $meta = null;
-	protected ?MetaForm $form = null;
-
 	// UI Options
 	protected array $stuck = []; // Fields that stick when scrolling
 	protected bool $showHeader = true;
@@ -134,6 +129,7 @@
 	protected array $additionalClasses = [];
 
 	public function __construct() {
+		$this->icon = jvbDefaultIcon();
 		$this->user = wp_get_current_user();
 		$this->user_id = $this->user->ID;
 	}
@@ -229,6 +225,20 @@
 		return $this;
 	}
 
+	protected function taxConfig(string $taxonomy, string $label = ''):array
+	{
+		$isVerified = jvbUserIsVerified();
+		$label = ($label === '') ? JVB_TAXONOMY[$taxonomy]['plural'] : $label;
+		return [
+			'type'		=> 'taxonomy',
+			'label'		=> $label,
+			'taxonomy'	=> $taxonomy,
+			'createNew' => $isVerified,
+			'multiple'	=> true,
+			'mode'		=> 'append',
+		];
+	}
+
 	public function addSearch():self
 	{
 		$this->hasSearch = true;
@@ -331,9 +341,7 @@
 			}
 			return false;
 		}));
-		array_unshift($this->timelineSharedFields, 'post_thumbnail');
 		array_unshift($this->timelineSharedFields, 'post_title');
-		array_unshift($this->timelineSharedFields, 'post_status');
 
 		$this->timelineUniqueFields = array_keys(array_filter($this->fields, function ($field) {
 			if (array_key_exists('for_all', $field) && $field['for_all'] === true) {
@@ -342,6 +350,7 @@
 			return false;
 		}));
 
+
 		$all = array_merge($this->timelineUniqueFields, $this->timelineSharedFields);
 		$this->nonTimelineFields = array_filter($this->fields, function ($field) use ($all) {
 			return !in_array($field, $all);
@@ -484,14 +493,6 @@
 		return $this;
 	}
 
-	/**
-	 * Initialize meta handling
-	 */
-	public function initMeta(string $objectType = 'post', ?string $content = null): self {
-		$this->meta = new MetaManager(null, $objectType, $content ?? $this->dataType);
-		$this->form = new MetaForm();
-		return $this;
-	}
 
 	/**
 	 * Build the configuration array
@@ -526,7 +527,7 @@
 		$config = $this->build();
 		$classes = array_merge(['dashboard-page', $this->dataType], $this->additionalClasses);
 
-		ob_start();
+//		ob_start();
 		?>
 		<div class="<?= esc_attr(implode(' ', $classes)) ?>" data-type="<?= esc_attr($this->dataType) ?>">
 			<?php
@@ -539,7 +540,7 @@
 			?>
 		</div>
 		<?php
-		echo ob_get_clean();
+//		echo ob_get_clean();
 	}
 
 	/**
@@ -566,16 +567,13 @@
 	 * Render uploader section
 	 */
 	protected function renderUploader(): void {
-		if (!$this->meta) {
-			return;
-		}
 		?>
 		<details open class="uploader">
 			<summary class="row btw"><?= esc_html($this->uploaderConfig['label'] ?? 'Upload Files') ?></summary>
 			<?php
-			$this->meta->render(
-				'form',
+			echo Form::render(
 				'new_' . $this->dataType,
+				null,
 				$this->uploaderConfig
 			);
 			?>
@@ -589,17 +587,19 @@
 	protected function renderContent(): void {
 		$dataIgnore = $this->useCRUDjs ? '' : ' data-ignore';
 		?>
-		<section class="items-list <?= esc_attr($this->dataType) ?> crud" data-content="<?= esc_attr($this->dataType) ?>" data-view="<?= $this->defaultView?>"<?=$dataIgnore?>>
-			<?php
-			$this->renderControlsAndFilters();
+		<section class="items-list <?= esc_attr($this->dataType) ?> crud" data-content="<?= esc_attr($this->dataType) ?>" data-singular="<?=$this->singular?>" data-plural="<?=$this->plural?>" data-view="<?= $this->defaultView?>"<?=$dataIgnore?>>
+			<div class="wrap">
+				<?php
+				$this->renderControlsAndFilters();
 
-			if ($this->showBulkControls) {
-				$this->renderBulkActions();
-			}
-			?>
+				if ($this->showBulkControls) {
+					$this->renderBulkActions();
+				}
+				?>
 
-			<div class="<?= esc_attr($this->dataType) ?> item-grid" role="grid"></div>
-			<div class="scroll-sentinel" aria-hidden="true"></div>
+				<div class="<?= esc_attr($this->dataType) ?> item-grid" role="grid"></div>
+				<div class="scroll-sentinel" aria-hidden="true"></div>
+			</div>
 		</section>
 		<?php
 	}
@@ -613,7 +613,7 @@
 		}
 		?>
 		<details class="all-filters col start" data-ignore>
-			<summary>Filters</summary>
+			<summary>Filters <button hidden data-action="clear-filters" data-ignore><?=jvbIcon('x')?><span>Clear Filters</span></span></button></summary>
 			<?php
 
 			$this->renderSearch();
@@ -625,6 +625,7 @@
 				$this->renderColumnSelector();
 			}
 			?>
+			<button data-action="refresh" data-ignore><?=jvbIcon('arrows-clockwise')?><span>Hard Refresh</span></span></button>
 		</details>
 		<?php
 	}
@@ -732,8 +733,11 @@
 					$i = 0;
 					foreach ($option as $opt => $label) {
 						$icon = $opt === 'date' ? 'calendar' : $opt;
+						$value = $opt;
+						$value = ($value === 'sort-ascending') ? 'asc' : $value;
+						$value = ($value === 'sort-descending') ? 'desc' : $value;
 						?>
-						<input id="<?=$opt?>" class="btn" type="radio" name="<?=$o?>" data-filter="<?=$o?>" value="<?=$opt?>"<?=$i===0 ? ' checked':''?>>
+						<input id="<?=$opt?>" class="btn" type="radio" name="<?=$o?>" data-filter="<?=$o?>" value="<?=$value?>"<?=$i===0 ? ' checked':''?>>
 
 						<label for="<?=$opt?>" title="<?=$label?>"><?=jvbDashIcon($icon)?></label>
 						<?php
@@ -807,11 +811,11 @@
 					<label for="date-start" class="col">
 						From
 					</label>
-					<input type="date" id="date-start" class="date-start">
+					<input type="date" id="date-start" class="date-start" name="date-start">
 					<label for="date-end" class="col">
 					   To
 					</label>
-					<input type="date" id="date-end" class="date-end">
+					<input type="date" id="date-end" class="date-end" name="date-end">
 				</div>
 				<div class="month-picker">
 					<label>
@@ -855,7 +859,7 @@
 		$out = '';
 		if (!empty($terms)) {
 			$out .= sprintf(
-				'<div class="row nowrap"><label for="filter-%s">%s<span class="screen-reader-text">Filter by %s</span></label>
+				'<div class="row nowrap"><label class="m-0" for="filter-%s">%s<span class="screen-reader-text">Filter by %s</span></label>
                 <select id="filter-%s" class="filter %s" name="%s" data-filter="taxonomies" data-taxonomy="%s">
                 <option value="">by %s</option>',
 				$taxonomy,
@@ -971,7 +975,7 @@
 				}
 				foreach ($this->taxonomies as $taxonomy => $config) {
 					?>
-					<option value="tax-<?=$taxonomy?>">Add to <?= JVB_TAXONOMY[$taxonomy]['singular']??$config['label'] ?></option>
+					<option value="tax-<?=$taxonomy?>" data-type="selector" data-single="<?=JVB_TAXONOMY[$taxonomy]['singular']?>" data-plural="<?=JVB_TAXONOMY[$taxonomy]['plural']?>" data-taxonomy="<?=$taxonomy?>">Add to <?= JVB_TAXONOMY[$taxonomy]['singular']??$config['label'] ?></option>
 					<?php
 				}
 				?>
@@ -1037,10 +1041,9 @@
 			$temp = array_filter($this->fields, function ($field) {
 				return in_array($field, $this->timelineUniqueFields);
 			}, ARRAY_FILTER_USE_KEY);
-			jvbDump($temp);
-			$form = new MetaForm();
+
 			echo '<template class="timelineItem">';
-			$form->renderImagePreview(null,['fields' => $temp]);
+			echo Form::renderImagePreview(null, ['fields' => $temp]);
 			echo '</template>';
 		}
 		if (!array_key_exists('empty', $templates)) {
@@ -1093,8 +1096,8 @@
 		ob_start();
 		?>
 		<div class="item-select">
-			<input type="checkbox" class="select-item">
-			<label class="select-item-label">
+			<input type="checkbox" class="select-item" name="select-item" id="item">
+			<label class="select-item-label" for="item">
 				<span class="screen-reader-text">Select this <?= $this->singular ?></span>
 			</label>
 		</div>
@@ -1155,11 +1158,11 @@
 				<?= $this->renderItemSelect()?>
 				<?=$this->renderImage() ?>
 				<div class="col start w-full">
-					<?= $this->renderItemActions()?>
 					<h3 data-field="post_title"></h3>
 					<p data-attr="date"></p>
 					<p data-field="price"></p>
 					<div data-field="post_excerpt"></div>
+					<?= $this->renderItemActions()?>
 				</div>
 			</div>
 		</template>
@@ -1242,7 +1245,11 @@
 						<?php
 						if (in_array('edit', $this->caps)) {
 							echo $makeThisDetailed ? '<details><summary class="row btw">See Value</summary>' : '';
-							echo $this->meta->render('form', $name, $config);
+							if (in_array($config['type'], ['selector', 'taxonomy', 'post'])) {
+								$config['autocomplete'] = true;
+							}
+
+							echo Form::render($name, null, $config);
 							echo $makeThisDetailed ? '</details>' : '';
 						} else {
 							echo '<p></p>';
@@ -1320,7 +1327,12 @@
 					?>
 					<td class="field show-<?= esc_attr($name) ?>" data-field="<?= esc_attr($name) ?>" data-field-type="<?=$config['type']?>"<?=(in_array($name, $this->stuck)) ? ' data-stuck':''?>>
 						<?= $makeThisDetailed ? '<details><summary class="row btw">See Value</summary>' : '' ?>
-						<?php $this->meta->render('form', $name, $config); ?>
+						<?php
+						if (in_array($config['type'], ['selector', 'taxonomy', 'post'])) {
+							$config['autocomplete'] = true;
+						}
+						?>
+						<?= Form::render($name, null, $config); ?>
 						<?= $makeThisDetailed ? '</details>' : '' ?>
 					</td>
 					<?php
@@ -1348,7 +1360,7 @@
 					?>
 					<td class="field show-<?= esc_attr($name) ?>" data-field="<?= esc_attr($name) ?>" data-field-type="<?=$config['type']?>"<?=(in_array($name, $this->stuck)) ? ' data-stuck':''?>>
 						<?= $makeThisDetailed ? '<details><summary class="row btw">See Value</summary>' : '' ?>
-						<?php $this->meta->render('form', $name, $config); ?>
+						<?= Form::render($name, null, $config); ?>
 						<?= $makeThisDetailed ? '</details>' : '' ?>
 					</td>
 					<?php
@@ -1452,10 +1464,10 @@
 	protected function renderStatusRadios(): string {
 		ob_start();
 		?>
-		<div class="radio-options status-options row">
+		<div class="radio-options status-options row" data-field="post_status" data-field-type="radio">
 			<?php foreach ($this->statuses as $status):
 				if ($status === 'all') continue;
-				if (!in_array($status, $this->allowedStatuses)) continue;
+				if (!array_key_exists($status, $this->allowedStatuses)) continue;
 				$config = $this->allowedStatuses[$status];
 				?>
 
@@ -1468,6 +1480,7 @@
 					<span class="screen-reader-text"><?= esc_html($config['label']) ?></span>
 				</label>
 			<?php endforeach; ?>
+			<span class="validation-message" hidden role="alert"></span>
 		</div>
 		<?php
 		return ob_get_clean();
@@ -1530,7 +1543,7 @@
 			<input type="hidden" name="form-id" value="<?=uniqid('new-')?>" />
 			<input type="hidden" name="content" value="<?=$this->dataType?>" />
 			<div class="fields">
-				<div class="field-group radio-options row">
+				<div class="field-group radio-options row" data-field="post_status" data-field-type="radio">
 					<span>Status:</span>
 					<?php
 					$this->getApplicableStatuses('edit');
@@ -1571,9 +1584,9 @@
 					foreach ($first as $f) {
 						if (array_key_exists($f, $fields)) {
 							if ($tabs) {
-								$tabs['basic']['content'] .= $this->meta->render('form', $f, $fields[$f], false, true);
+								$tabs['basic']['content'] .= Form::render($f, null, $fields[$f]);
 							} else {
-								$this->meta->render('form', $f, $fields[$f]);
+								Form::render($f, null, $fields[$f]);
 							}
 
 							unset($fields[$f]);
@@ -1585,7 +1598,6 @@
 					$temp = array_filter($fields, function ($field) {
 						return in_array($field, $this->timelineUniqueFields);
 					}, ARRAY_FILTER_USE_KEY);
-
 					$config = [
 						'type'		=> 'gallery',
 						'subtype'	=> 'timeline',
@@ -1596,12 +1608,15 @@
 					$content = '';
 					foreach ($fields as $slug=> $field) {
 						if (in_array($slug, $this->timelineSharedFields)) {
-							$content .= $this->form->render($slug, null, $field, false, true);
+							if (in_array($field['type'], ['taxonomy', 'selector'])) {
+								$field = array_merge($field, $this->taxConfig($field['taxonomy'], $field['label']));
+							}
+							$content .= Form::render($slug, null, $field);
 						}
 					}
 
 
-					$content .= $this->meta->render('form', 'timeline', $config, false,true);
+					$content .= Form::render('timeline', null, $config);
 
 					$tabs['progression']['content'] = $content;
 					$fields = $this->nonTimelineFields;
@@ -1609,9 +1624,12 @@
 				foreach ($fields as $n => $config) {
 					if ($tabs) {
 						$section = (array_key_exists('section', $config)) ? $config['section'] : 'basic';
-						$tabs[$section]['content'] .= $this->meta->render('form', $n, $config, false, true);
+						$tabs[$section]['content'] .= Form::render($n,null, $config);
 					} else {
-						$this->meta->render('form', $n, $config);
+						if (in_array($config['type'], ['taxonomy', 'selector'])) {
+							$config = array_merge($config, $this->taxConfig($config['taxonomy'], $config['label']));
+						}
+						Form::render($n, null, $config);
 					}
 				}
 
@@ -1623,6 +1641,7 @@
 		</form>
 		<?php
 		return ob_get_clean();
+//		return '';
 	}
 
 	protected function renderEditModal():void
@@ -1656,18 +1675,7 @@
 					<div class="taxonomies">
 						<?php
 						foreach ($this->taxonomies as $taxonomy => $config) {
-							$this->meta->render(
-								'form',
-								'bulk-edit-'.$taxonomy,
-								[
-									'type'		=> 'taxonomy',
-									'label'		=> $config['label'],
-									'taxonomy'	=> $taxonomy,
-									'createNew'	=> jvbUserIsVerified(),
-									'multiple'	=> true,
-									'mode'		=> 'append'
-								]
-							);
+							echo Form::render('bulk-edit-'.$taxonomy, '', $this->taxConfig($taxonomy, $config['label']));
 						}
 						?>
 					</div>
@@ -1678,7 +1686,7 @@
 					return array_key_exists('bulkEdit', $field);
 				});
 				foreach ($fields as $fieldName => $config) {
-					$this->meta->render('form', $fieldName, $config);
+					echo Form::render($fieldName, null, $config);
 				}
 				?>
 			</div>

--
Gitblit v1.10.0