From 48721c85ebcfa973ee81719d2467ca80e4253dc9 Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Fri, 01 May 2026 17:30:03 +0000
Subject: [PATCH] =Edmonton Ink hard test begins! Real testing of the managers and reset routes will commence. So far, just ensuring our classes are all loaded correctly: Site() and its sub-classes Membership, Login, etc. Care should be taken to load conditionally on 'init', as we finish defining most settings by 'plugins_loaded' at priority 5
---
inc/ui/CRUDSkeleton.php | 255 +++++++++++++++++++++++++++++++--------------------
1 files changed, 155 insertions(+), 100 deletions(-)
diff --git a/inc/ui/CRUDSkeleton.php b/inc/ui/CRUDSkeleton.php
index e8c0478..c62f3a4 100644
--- a/inc/ui/CRUDSkeleton.php
+++ b/inc/ui/CRUDSkeleton.php
@@ -1,9 +1,10 @@
<?php
namespace JVBase\ui;
+use JVBase\base\Site;
use JVBase\managers\UserTermsManager;
-use JVBase\meta\MetaForm;
-use JVBase\meta\MetaManager;
+use JVBase\meta\Form;
+use JVBase\registrar\Registrar;
use WP_User;
if (!defined('ABSPATH')) {
@@ -121,10 +122,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;
@@ -133,6 +130,7 @@
protected array $customDateRanges = [];
protected array $additionalClasses = [];
+ protected Registrar $registrar;
public function __construct() {
$this->icon = jvbDefaultIcon();
$this->user = wp_get_current_user();
@@ -153,6 +151,7 @@
*/
public function content(string $type, string $singular, string $plural): self {
$this->dataType = $type;
+ $this->registrar = Registrar::getInstance($type);
$this->singular = $singular;
$this->plural = $plural;
return $this;
@@ -218,18 +217,43 @@
*/
public function addTaxonomyFilter(array $taxonomies, ?string $limit = null): self {
foreach($taxonomies as $taxonomy) {
- $this->taxonomies[$taxonomy] = [
- 'type' => 'taxonomy',
- 'taxonomy'=> $taxonomy,
- 'limit' => $limit,
- 'label' => JVB_TAXONOMY[$taxonomy]['plural']??'',
- 'icon' => JVB_TAXONOMY[$taxonomy]['icon']??''
- ];
+ $registrar = Registrar::getInstance($taxonomy);
+
+ if ($registrar) {
+ $this->taxonomies[$taxonomy] = [
+ 'type' => 'taxonomy',
+ 'taxonomy'=> $taxonomy,
+ 'limit' => $limit,
+ 'label' => $registrar->getPlural(),
+ 'icon' => $registrar->getIcon()
+ ];
+ }
}
return $this;
}
+ protected function taxConfig(string $taxonomy, string $label = ''):array
+ {
+ $isVerified = $this->userIsVerified();
+ $label = ($label === '') ? Registrar::getInstance($taxonomy)->getPlural() : $label;
+ return [
+ 'type' => 'taxonomy',
+ 'label' => $label,
+ 'taxonomy' => $taxonomy,
+ 'createNew' => $isVerified,
+ 'multiple' => true,
+ 'mode' => 'append',
+ ];
+ }
+
+ protected function userIsVerified():bool
+ {
+ $membership = Site::membership();
+
+ return !($membership && $membership->has('member_verified')) || current_user_can('skip_moderation');
+ }
+
public function addSearch():self
{
$this->hasSearch = true;
@@ -332,9 +356,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) {
@@ -343,6 +365,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);
@@ -485,14 +508,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
@@ -527,7 +542,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
@@ -540,7 +555,7 @@
?>
</div>
<?php
- echo ob_get_clean();
+// echo ob_get_clean();
}
/**
@@ -567,16 +582,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
);
?>
@@ -590,17 +602,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
}
@@ -614,7 +628,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();
@@ -626,6 +640,7 @@
$this->renderColumnSelector();
}
?>
+ <button data-action="refresh" data-ignore><?=jvbIcon('arrows-clockwise')?><span>Hard Refresh</span></span></button>
</details>
<?php
}
@@ -733,8 +748,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
@@ -808,11 +826,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>
@@ -856,7 +874,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,
@@ -891,7 +909,7 @@
if ($limit) {
if ($limit === 'user') {
$manager = new UserTermsManager();
- return $manager->getUserTerms($this->user_id, $taxonomy);
+ return $manager->fetchUserTerms($this->user_id, $taxonomy);
} else {
$limit = (int)$limit;
}
@@ -970,9 +988,12 @@
<option value="<?=$control?>"<?=$disabled?>><?=$label?></option>
<?php
}
- foreach ($this->taxonomies as $taxonomy => $config) {
+
+ foreach ($this->taxonomies as $taxonomy =>$config) {
+ $registrar = Registrar::getInstance($taxonomy);
+ if (!$registrar) continue;
?>
- <option value="tax-<?=$taxonomy?>">Add to <?= JVB_TAXONOMY[$taxonomy]['singular']??$config['label'] ?></option>
+ <option value="tax-<?=$taxonomy?>" data-type="selector" data-single="<?=$registrar->getSingular()?>" data-plural="<?=$registrar->getPlural()?>" data-taxonomy="<?=$taxonomy?>">Add to <?= $registrar->getSingular() ?></option>
<?php
}
?>
@@ -1038,10 +1059,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)) {
@@ -1094,8 +1114,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>
@@ -1156,11 +1176,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>
@@ -1243,7 +1263,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>';
@@ -1321,7 +1345,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
@@ -1349,7 +1378,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
@@ -1453,10 +1482,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];
?>
@@ -1469,6 +1498,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();
@@ -1531,19 +1561,17 @@
<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">
- <span>Status:</span>
- <?php
- $this->getApplicableStatuses('edit');
- ?>
- </div>
- <?php if (!$this->userCanPublish) { ?>
- <p class="description">Your account needs to be verified before you can publish content.</p>
- <?php }
+ <?php
+ if (!empty($this->statuses)) {
+ echo Form::render('post_status', '', $this->getStatusFieldConfig('edit-'));
+ }
+
+
if (!empty($this->sections)) {
$tabs = [];
- foreach ($this->sections as $slug => $config) {
+ foreach ($this->sections as $config) {
+ $slug = $config['slug'];
$section = [];
if (array_key_exists('icon', $config)) {
$section = [
@@ -1555,16 +1583,11 @@
'content' => '',
'description' => $config['description']??'',
], $section);
- $icon = jvbSectionIcon($slug);
- if ($icon !== '') {
- $tabs[$slug]['icon'] = $icon;
- }
}
} else {
$tabs = false;
}
-
$fields = $this->fields;
if (!$this->isTimeline) {
$first = ['post_thumbnail', 'post_title', 'price'];
@@ -1572,11 +1595,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]);
}
}
@@ -1586,9 +1608,8 @@
$temp = array_filter($fields, function ($field) {
return in_array($field, $this->timelineUniqueFields);
}, ARRAY_FILTER_USE_KEY);
-
$config = [
- 'type' => 'gallery',
+ 'type' => 'upload',
'subtype' => 'timeline',
'data' => 'timeline',
'label' => 'Progression',
@@ -1597,22 +1618,28 @@
$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, '', $field);
}
}
- $content .= $this->meta->render('form', 'timeline', $config, false,true);
+ $content .= Form::render('timeline', '', $config);
$tabs['progression']['content'] = $content;
$fields = $this->nonTimelineFields;
}
foreach ($fields as $n => $config) {
+ if (in_array($config['type'], ['taxonomy', 'selector'])) {
+ $config = array_merge($config, $this->taxConfig($config['taxonomy'], $config['label']));
+ }
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 {
- $this->meta->render('form', $n, $config);
+ echo Form::render($n, '', $config);
}
}
@@ -1624,6 +1651,7 @@
</form>
<?php
return ob_get_clean();
+// return '';
}
protected function renderEditModal():void
@@ -1646,29 +1674,15 @@
<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
+ echo Form::render('post_status', '', $this->getStatusFieldConfig('bulk-'));
+
if (!empty($this->taxonomies)) {
?>
<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>
@@ -1679,7 +1693,7 @@
return array_key_exists('bulkEdit', $field);
});
foreach ($fields as $fieldName => $config) {
- $this->meta->render('form', $fieldName, $config);
+ echo Form::render($fieldName, '', $config);
}
?>
</div>
@@ -1699,7 +1713,46 @@
);
}
+ protected function getStatusFieldConfig(string $prefix): array
+ {
+ $options = [];
+ foreach ($this->statuses as $status) {
+ if ($status === 'all' || !array_key_exists($status, $this->allowedStatuses)) {
+ continue;
+ }
+ $config = $this->allowedStatuses[$status];
+
+ if (in_array($status, ['future', 'past'])) {
+ if ($status === 'future') {
+ $status = 'publish';
+ $config = ['icon' => 'eye', 'label' => 'Live'];
+ } else {
+ continue;
+ }
+ }
+
+ $options[$status] = [
+ 'label' => $config['label'],
+ 'icon' => $config['icon'],
+ 'disabled' => ($status === 'publish' && !$this->userCanPublish),
+ ];
+ }
+
+ return [
+ 'type' => 'radio',
+ 'label' => 'Status',
+ 'options' => $options,
+ 'inputClass' => 'btn',
+ 'idPrefix' => $prefix,
+ 'class' => 'radio-options row',
+ 'hint' => !$this->userCanPublish
+ ? 'Your account needs to be verified before you can publish content.'
+ : '',
+ ];
+ }
+
protected function getApplicableStatuses(string $prefix) {
+ ob_start();
foreach ($this->statuses as $status) {
if ($status === 'all' || !array_key_exists($status, $this->allowedStatuses)) {
continue;
@@ -1729,5 +1782,7 @@
</label>
<?php
}
+ $out = ob_get_clean();
+ echo Form::fieldWrap('post_status', $out, ['type'=>'group']);
}
}
--
Gitblit v1.10.0