Jake Vanderwerf
2026-03-08 c19264ac916707096fe294d996a1b7fb85206b34
inc/ui/CRUDSkeleton.php
@@ -3,6 +3,7 @@
use JVBase\managers\UserTermsManager;
use JVBase\meta\Form;
use JVBase\registrar\Registrar;
use WP_User;
if (!defined('ABSPATH')) {
@@ -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,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;
@@ -213,13 +216,18 @@
    */
   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']??''
         ];
         error_log('Fetchinig taxonomy: '.print_r($taxonomy, true));
         $registrar = Registrar::getInstance($taxonomy);
         if ($registrar) {
            $this->taxonomies[$taxonomy] = [
               'type'   => 'taxonomy',
               'taxonomy'=> $taxonomy,
               'limit'  => $limit,
               'label'  => $registrar->getPlural(),
               'icon'   => $registrar->getIcon()
            ];
         }
      }
      return $this;
@@ -228,7 +236,7 @@
   protected function taxConfig(string $taxonomy, string $label = ''):array
   {
      $isVerified = jvbUserIsVerified();
      $label = ($label === '') ? JVB_TAXONOMY[$taxonomy]['plural'] : $label;
      $label = ($label === '') ? Registrar::getInstance($taxonomy)->getPlural() : $label;
      return [
         'type'      => 'taxonomy',
         'label'     => $label,
@@ -573,7 +581,7 @@
         <?php
         echo Form::render(
            'new_' . $this->dataType,
            null,
            '',
            $this->uploaderConfig
         );
         ?>
@@ -973,9 +981,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
            }
            ?>
@@ -1249,7 +1260,7 @@
                        $config['autocomplete'] = true;
                     }
                     echo Form::render($name, null, $config);
                     echo Form::render($name, '', $config);
                     echo $makeThisDetailed ? '</details>' : '';
                  } else {
                     echo '<p></p>';
@@ -1332,7 +1343,7 @@
                     $config['autocomplete'] = true;
                  }
                  ?>
                  <?= Form::render($name, null, $config); ?>
                  <?= Form::render($name, '', $config); ?>
                  <?= $makeThisDetailed ? '</details>' : '' ?>
               </td>
               <?php
@@ -1360,7 +1371,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>' : '' ?>
                  <?= Form::render($name, null, $config); ?>
                  <?= Form::render($name, '', $config); ?>
                  <?= $makeThisDetailed ? '</details>' : '' ?>
               </td>
               <?php
@@ -1543,19 +1554,14 @@
         <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
            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,16 +1573,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'];
@@ -1584,11 +1585,10 @@
               foreach ($first as $f) {
                  if (array_key_exists($f, $fields)) {
                     if ($tabs) {
                        $tabs['basic']['content'] .= Form::render($f, null, $fields[$f]);
                        $tabs['basic']['content'] .= Form::render($f, '', $fields[$f]);
                     } else {
                        Form::render($f, null, $fields[$f]);
                        echo Form::render($f, '', $fields[$f]);
                     }
                     unset($fields[$f]);
                  }
               }
@@ -1599,7 +1599,7 @@
                  return in_array($field, $this->timelineUniqueFields);
               }, ARRAY_FILTER_USE_KEY);
               $config = [
                  'type'      => 'gallery',
                  'type'      => 'upload',
                  'subtype'   => 'timeline',
                  'data'      => 'timeline',
                  'label'     => 'Progression',
@@ -1611,25 +1611,25 @@
                     if (in_array($field['type'], ['taxonomy', 'selector'])) {
                        $field = array_merge($field, $this->taxConfig($field['taxonomy'], $field['label']));
                     }
                     $content .= Form::render($slug, null, $field);
                     $content .= Form::render($slug, '', $field);
                  }
               }
               $content .= Form::render('timeline', null, $config);
               $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'] .= Form::render($n,null, $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']));
                  }
                  Form::render($n, null, $config);
                  echo Form::render($n, '', $config);
               }
            }
@@ -1664,12 +1664,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">
@@ -1686,7 +1683,7 @@
               return array_key_exists('bulkEdit', $field);
            });
            foreach ($fields as $fieldName => $config) {
               echo Form::render($fieldName, null, $config);
               echo Form::render($fieldName, '', $config);
            }
            ?>
         </div>
@@ -1706,7 +1703,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;
@@ -1736,5 +1772,7 @@
         </label>
         <?php
      }
      $out = ob_get_clean();
      echo Form::fieldWrap('post_status', $out, ['type'=>'group']);
   }
}