From bf69b2c2daeb2d5c1f9b1b3dfe99bfb62a739a9a Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Tue, 10 Feb 2026 02:42:15 +0000
Subject: [PATCH] =more CRUDSkeleton
---
inc/ui/CRUDSkeleton.php | 96 +++++++++++++++++++++---------------------------
1 files changed, 42 insertions(+), 54 deletions(-)
diff --git a/inc/ui/CRUDSkeleton.php b/inc/ui/CRUDSkeleton.php
index ecef889..e74a010 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')) {
@@ -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;
@@ -346,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) {
@@ -357,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);
@@ -499,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
@@ -541,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
@@ -554,7 +540,7 @@
?>
</div>
<?php
- echo ob_get_clean();
+// echo ob_get_clean();
}
/**
@@ -581,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,
+ '',
$this->uploaderConfig
);
?>
@@ -1058,9 +1041,9 @@
$temp = array_filter($this->fields, function ($field) {
return in_array($field, $this->timelineUniqueFields);
}, ARRAY_FILTER_USE_KEY);
- $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)) {
@@ -1113,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>
@@ -1262,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, '', $config);
echo $makeThisDetailed ? '</details>' : '';
} else {
echo '<p></p>';
@@ -1340,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, '', $config); ?>
<?= $makeThisDetailed ? '</details>' : '' ?>
</td>
<?php
@@ -1368,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, '', $config); ?>
<?= $makeThisDetailed ? '</details>' : '' ?>
</td>
<?php
@@ -1472,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];
?>
@@ -1488,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();
@@ -1550,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');
@@ -1583,7 +1576,6 @@
$tabs = false;
}
-
$fields = $this->fields;
if (!$this->isTimeline) {
$first = ['post_thumbnail', 'post_title', 'price'];
@@ -1591,11 +1583,10 @@
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, '', $fields[$f]);
} else {
- $this->meta->render('form', $f, $fields[$f]);
+ echo Form::render($f, '', $fields[$f]);
}
-
unset($fields[$f]);
}
}
@@ -1606,7 +1597,7 @@
return in_array($field, $this->timelineUniqueFields);
}, ARRAY_FILTER_USE_KEY);
$config = [
- 'type' => 'gallery',
+ 'type' => 'upload',
'subtype' => 'timeline',
'data' => 'timeline',
'label' => 'Progression',
@@ -1618,12 +1609,12 @@
if (in_array($field['type'], ['taxonomy', 'selector'])) {
$field = array_merge($field, $this->taxConfig($field['taxonomy'], $field['label']));
}
- $content .= $this->form->render($slug, null, $field, false, true);
+ $content .= Form::render($slug, '', $field);
}
}
- $content .= $this->meta->render('form', 'timeline', $config, false,true);
+ $content .= Form::render('timeline', '', $config);
$tabs['progression']['content'] = $content;
$fields = $this->nonTimelineFields;
@@ -1631,12 +1622,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,'', $config);
} else {
if (in_array($config['type'], ['taxonomy', 'selector'])) {
$config = array_merge($config, $this->taxConfig($config['taxonomy'], $config['label']));
}
- $this->meta->render('form', $n, $config);
+ echo Form::render($n, '', $config);
}
}
@@ -1648,6 +1639,7 @@
</form>
<?php
return ob_get_clean();
+// return '';
}
protected function renderEditModal():void
@@ -1670,23 +1662,16 @@
<p class="description">You can unselect items by clicking the image here.</p>
<p class="hint"><strong>IMPORTANT: </strong> Whatever changes you make here will be applied to all selected <?=$this->plural?>.</p>
<div class="fields">
- <div class="field-group radio-options row">
- <?php
- $this->getApplicableStatuses('bulk-');
- ?>
- </div>
+ <?php
+ $this->getApplicableStatuses('bulk-');
+ ?>
<?php
if (!empty($this->taxonomies)) {
?>
<div class="taxonomies">
<?php
foreach ($this->taxonomies as $taxonomy => $config) {
- $this->form->renderSelectorField(
- 'bulk-edit-'.$taxonomy,
- '',
- $this->taxConfig($taxonomy, $config['label']),
- 'taxonomy'
- );
+ echo Form::render('bulk-edit-'.$taxonomy, '', $this->taxConfig($taxonomy, $config['label']));
}
?>
</div>
@@ -1697,7 +1682,7 @@
return array_key_exists('bulkEdit', $field);
});
foreach ($fields as $fieldName => $config) {
- $this->meta->render('form', $fieldName, $config);
+ echo Form::render($fieldName, '', $config);
}
?>
</div>
@@ -1718,6 +1703,7 @@
}
protected function getApplicableStatuses(string $prefix) {
+ ob_start();
foreach ($this->statuses as $status) {
if ($status === 'all' || !array_key_exists($status, $this->allowedStatuses)) {
continue;
@@ -1747,5 +1733,7 @@
</label>
<?php
}
+ $out = ob_get_clean();
+ echo Form::fieldWrap('post_status', $out, ['type'=>'group']);
}
}
--
Gitblit v1.10.0