From 46d681c6b825d21b3f698d793c4e630c687d90ad Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Thu, 21 May 2026 21:41:53 +0000
Subject: [PATCH] =Major CustomBlocks.php overhaul, expanding block support and customization from the editor. theme.json should now be updated on new themes to set brand colours, etc. Also note: major change to .col vs .row alignment: simplifying it to .top .bottom vs the confusion of the differences for .col/.row .start and .a-start
---
inc/ui/CRUDSkeleton.php | 212 +++++++++++++++++++++++++++++++++--------------------
1 files changed, 132 insertions(+), 80 deletions(-)
diff --git a/inc/ui/CRUDSkeleton.php b/inc/ui/CRUDSkeleton.php
index d15ea2e..307e0b9 100644
--- a/inc/ui/CRUDSkeleton.php
+++ b/inc/ui/CRUDSkeleton.php
@@ -1,8 +1,10 @@
<?php
namespace JVBase\ui;
+use JVBase\base\Site;
use JVBase\managers\UserTermsManager;
use JVBase\meta\Form;
+use JVBase\registrar\Registrar;
use WP_User;
if (!defined('ABSPATH')) {
@@ -117,7 +119,6 @@
protected ?array $uploaderConfig = null;
// Data
- protected $dataSourceCallback = null;
protected array $templates = [];
// UI Options
@@ -128,6 +129,7 @@
protected array $customDateRanges = [];
protected array $additionalClasses = [];
+ protected ?Registrar $registrar;
public function __construct() {
$this->icon = jvbDefaultIcon();
$this->user = wp_get_current_user();
@@ -148,6 +150,12 @@
*/
public function content(string $type, string $singular, string $plural): self {
$this->dataType = $type;
+ $registrar = Registrar::getInstance($type);
+ if ($registrar) {
+ $this->registrar = Registrar::getInstance($type)??null;
+ $this->sections = $this->registrar->getSections();
+ }
+
$this->singular = $singular;
$this->plural = $plural;
return $this;
@@ -213,13 +221,17 @@
*/
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;
@@ -227,8 +239,8 @@
protected function taxConfig(string $taxonomy, string $label = ''):array
{
- $isVerified = jvbUserIsVerified();
- $label = ($label === '') ? JVB_TAXONOMY[$taxonomy]['plural'] : $label;
+ $isVerified = $this->userIsVerified();
+ $label = ($label === '') ? Registrar::getInstance($taxonomy)->getPlural() : $label;
return [
'type' => 'taxonomy',
'label' => $label,
@@ -239,6 +251,13 @@
];
}
+ 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;
@@ -336,7 +355,7 @@
}
$this->timelineSharedFields = array_keys(array_filter($this->fields, function ($field) {
- if (!array_key_exists('for_all', $field) || $field['for_all'] === false){
+ if (!array_key_exists('for_all', $field) || $field['for_all'] === false || is_null($field['for_all'])){
return true;
}
return false;
@@ -350,7 +369,6 @@
return false;
}));
-
$all = array_merge($this->timelineUniqueFields, $this->timelineSharedFields);
$this->nonTimelineFields = array_filter($this->fields, function ($field) use ($all) {
return !in_array($field, $all);
@@ -451,15 +469,6 @@
}
/**
- * Set the data source callback
- * Callback should accept filters and return array of items
- */
- public function dataSource(callable $callback): self {
- $this->dataSourceCallback = $callback;
- return $this;
- }
-
- /**
* Add a custom template
*/
public function addTemplate(string $name, string $template): self {
@@ -569,14 +578,17 @@
protected function renderUploader(): void {
?>
<details open class="uploader">
- <summary class="row btw"><?= esc_html($this->uploaderConfig['label'] ?? 'Upload Files') ?></summary>
- <?php
- echo Form::render(
- 'new_' . $this->dataType,
- '',
- $this->uploaderConfig
- );
- ?>
+ <summary class="row x-btw"><?= esc_html($this->uploaderConfig['label'] ?? 'Upload Files') ?></summary>
+ <form id="uploader" data-form-id="upload_new_<?=$this->dataType ?>">
+ <?php
+ echo jvbFormRestore();
+ echo Form::render(
+ 'new_' . $this->dataType,
+ '',
+ $this->uploaderConfig
+ );
+ ?>
+ </form>
</details>
<?php
}
@@ -612,8 +624,8 @@
return;
}
?>
- <details class="all-filters col start" data-ignore>
- <summary>Filters <button hidden data-action="clear-filters" data-ignore><?=jvbIcon('x')?><span>Clear Filters</span></span></button></summary>
+ <details class="all-filters col top" data-ignore>
+ <summary>Filters</summary>
<?php
$this->renderSearch();
@@ -627,6 +639,7 @@
?>
<button data-action="refresh" data-ignore><?=jvbIcon('arrows-clockwise')?><span>Hard Refresh</span></span></button>
</details>
+ <button hidden data-action="clear-filters" data-ignore hidden><?=jvbIcon('x')?><span>Clear Filters</span></span></button>
<?php
}
@@ -636,7 +649,7 @@
return;
}
?>
- <div class="search row start nowrap">
+ <div class="search row left nowrap">
<span class="label">Search:</span>
<?= jvbSearch() ?>
</div>
@@ -712,7 +725,7 @@
protected function renderOrderControls():void
{
?>
- <div class="radio-options order row btw w-full">
+ <div class="radio-options order row x-btw w-full">
<?php
$order = [
'orderby' => [
@@ -727,7 +740,7 @@
foreach ($order as $o => $option) {
?>
- <div class="row start">
+ <div class="row left">
<span class="label"><?= ucfirst($o)?>:</span>
<?php
$i = 0;
@@ -757,7 +770,7 @@
return;
}
?>
- <div class="filters row start">
+ <div class="filters row left">
<span class="label">Filters:</span>
<?php
foreach ($this->filters as $key => $config) {
@@ -876,8 +889,8 @@
foreach ($terms as $term) {
$out .= sprintf(
'<option value="%s">%s</option>',
- esc_attr($term['term_id']),
- esc_html($term['name'])
+ esc_attr(is_object($term) ? $term->term_id : $term['term_id']),
+ esc_html(is_object($term) ? $term->name : $term['name'])
);
}
$out .= '</select></div>';
@@ -892,9 +905,9 @@
*/
protected function getCommonTerms(string $taxonomy, ?string $limit = null):array {
if ($limit) {
- if ($limit === 'user') {
+ if (Site::has('membership') && $limit === 'user') {
$manager = new UserTermsManager();
- return $manager->getUserTerms($this->user_id, $taxonomy);
+ return $manager->fetchUserTerms($this->user_id, $taxonomy);
} else {
$limit = (int)$limit;
}
@@ -915,7 +928,7 @@
ob_start();
?>
<details class="multi-select" title="Select columns" hidden>
- <summary class="row start nowrap">
+ <summary class="row left nowrap">
<?= jvbDashIcon('columns') ?>
<span class="labels">Toggle Columns</span>
</summary>
@@ -948,7 +961,7 @@
return;
}
?>
- <div class="bulk-controls row nowrap btw">
+ <div class="bulk-controls row nowrap x-btw">
<div class="bulk-select">
<input type="checkbox" id="select-all" class="select-all">
<label for="select-all" class="row"><span>Select All</span><span class="selected-count" hidden></span></label>
@@ -973,9 +986,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?>" 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>
+ <option value="tax-<?=$taxonomy?>" data-type="selector" data-single="<?=$registrar->getSingular()?>" data-plural="<?=$registrar->getPlural()?>" data-taxonomy="<?=$taxonomy?>">Add to <?= $registrar->getSingular() ?></option>
<?php
}
?>
@@ -1043,7 +1059,7 @@
}, ARRAY_FILTER_USE_KEY);
echo '<template class="timelineItem">';
- echo Form::renderImagePreview(null, ['fields' => $temp]);
+ echo Form::renderImagePreview(null, $temp);
echo '</template>';
}
if (!array_key_exists('empty', $templates)) {
@@ -1116,7 +1132,7 @@
}
ob_start();
?>
- <div class="item-actions row btw abs">
+ <div class="item-actions row x-btw abs">
<?php
foreach ($this->itemActions as $action) {
$config = $this->defaultItemActions[$action];
@@ -1157,7 +1173,7 @@
<div class="item <?=esc_attr($this->dataType)?> row nowrap">
<?= $this->renderItemSelect()?>
<?=$this->renderImage() ?>
- <div class="col start w-full">
+ <div class="col top w-full">
<h3 data-field="post_title"></h3>
<p data-attr="date"></p>
<p data-field="price"></p>
@@ -1244,7 +1260,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':''?>>
<?php
if (in_array('edit', $this->caps)) {
- echo $makeThisDetailed ? '<details><summary class="row btw">See Value</summary>' : '';
+ echo $makeThisDetailed ? '<details><summary class="row x-btw">See Value</summary>' : '';
if (in_array($config['type'], ['selector', 'taxonomy', 'post'])) {
$config['autocomplete'] = true;
}
@@ -1326,7 +1342,7 @@
$makeThisDetailed = (in_array($config['type'], $makeDetails));
?>
<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>' : '' ?>
+ <?= $makeThisDetailed ? '<details><summary class="row x-btw">See Value</summary>' : '' ?>
<?php
if (in_array($config['type'], ['selector', 'taxonomy', 'post'])) {
$config['autocomplete'] = true;
@@ -1359,7 +1375,7 @@
$makeThisDetailed = (in_array($config['type'], $makeDetails));
?>
<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>' : '' ?>
+ <?= $makeThisDetailed ? '<details><summary class="row x-btw">See Value</summary>' : '' ?>
<?= Form::render($name, '', $config); ?>
<?= $makeThisDetailed ? '</details>' : '' ?>
</td>
@@ -1442,7 +1458,7 @@
protected function renderTableActions(): string {
ob_start();
?>
- <div class="table-actions row btw nowrap">
+ <div class="table-actions row x-btw nowrap">
<?php if (count(array_intersect(['create', 'edit'], $this->caps)) > 0) { ?>
<?= jvbRenderToggleTextField(
'vertical',
@@ -1543,19 +1559,15 @@
<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" data-field="post_status" data-field-type="radio">
- <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 = [
@@ -1567,10 +1579,6 @@
'content' => '',
'description' => $config['description']??'',
], $section);
- $icon = jvbSectionIcon($slug);
- if ($icon !== '') {
- $tabs[$slug]['icon'] = $icon;
- }
}
} else {
$tabs = false;
@@ -1593,13 +1601,15 @@
}
if ($this->isTimeline) {
- $temp = array_filter($fields, function ($field) {
- return in_array($field, $this->timelineUniqueFields);
+ $temp = array_filter($fields, function ($field) use ($fields) {
+ return in_array($field, $this->timelineUniqueFields) && (!array_key_exists('hidden', $fields[$field]) || $fields[$field]['hidden'] === false);
}, ARRAY_FILTER_USE_KEY);
$config = [
'type' => 'upload',
'subtype' => 'timeline',
- 'data' => 'timeline',
+ 'multiple' => true,
+ 'limit' => 0,
+ 'data' => ['timeline'],
'label' => 'Progression',
'fields' => $temp
];
@@ -1609,24 +1619,31 @@
if (in_array($field['type'], ['taxonomy', 'selector'])) {
$field = array_merge($field, $this->taxConfig($field['taxonomy'], $field['label']));
}
- $content .= Form::render($slug, '', $field);
+ if (!array_key_exists('hidden', $field) || $field['hidden'] === false) {
+ $content .= Form::render($slug, '', $field);
+ }
}
}
- $content .= Form::render('timeline', '', $config);
+ $content .= Form::render('timeline_gallery', '', $config);
- $tabs['progression']['content'] = $content;
+ if ($tabs) {
+ $tabs['progression']['content'] = $content;
+ } else {
+ echo $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'] .= Form::render($n,'', $config);
+ $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']));
- }
echo Form::render($n, '', $config);
}
}
@@ -1662,12 +1679,9 @@
<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">
@@ -1704,6 +1718,44 @@
);
}
+ 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) {
@@ -1736,6 +1788,6 @@
<?php
}
$out = ob_get_clean();
- echo Form::buildInput($out);
+ echo Form::fieldWrap('post_status', $out, ['type'=>'group']);
}
}
--
Gitblit v1.10.0