From ac444cba221832c012c0435fdc8339fe9f37febb Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Mon, 11 May 2026 18:35:04 +0000
Subject: [PATCH] =Some changes to the CRUD.js editing, timeline post configuration

---
 inc/ui/CRUDSkeleton.php |   56 +++++++++++++++++++++++++++++---------------------------
 1 files changed, 29 insertions(+), 27 deletions(-)

diff --git a/inc/ui/CRUDSkeleton.php b/inc/ui/CRUDSkeleton.php
index c62f3a4..b5e977a 100644
--- a/inc/ui/CRUDSkeleton.php
+++ b/inc/ui/CRUDSkeleton.php
@@ -119,7 +119,6 @@
 	protected ?array $uploaderConfig = null;
 
 	// Data
-	protected $dataSourceCallback = null;
 	protected array $templates = [];
 
 	// UI Options
@@ -130,7 +129,7 @@
 	protected array $customDateRanges = [];
 	protected array $additionalClasses = [];
 
-	protected Registrar $registrar;
+	protected ?Registrar $registrar;
 	public function __construct() {
 		$this->icon = jvbDefaultIcon();
 		$this->user = wp_get_current_user();
@@ -151,7 +150,12 @@
 	 */
 	public function content(string $type, string $singular, string $plural): self {
 		$this->dataType = $type;
-		$this->registrar = Registrar::getInstance($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;
@@ -351,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;
@@ -365,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);
@@ -466,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 {
@@ -628,7 +622,7 @@
 		}
 		?>
 		<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>
+			<summary>Filters</summary>
 			<?php
 
 			$this->renderSearch();
@@ -642,6 +636,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
 	}
 
@@ -891,8 +886,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>';
@@ -907,7 +902,7 @@
 	 */
 	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->fetchUserTerms($this->user_id, $taxonomy);
 			} else {
@@ -1061,7 +1056,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)) {
@@ -1566,8 +1561,6 @@
 					echo Form::render('post_status', '', $this->getStatusFieldConfig('edit-'));
 				}
 
-
-
 				if (!empty($this->sections)) {
 					$tabs = [];
 					foreach ($this->sections as $config) {
@@ -1605,13 +1598,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
 					];
@@ -1621,14 +1616,21 @@
 							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) {

--
Gitblit v1.10.0