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/managers/DirectoryManager.php | 50 +++++++++++++++++++++++++++++++++++---------------
1 files changed, 35 insertions(+), 15 deletions(-)
diff --git a/inc/managers/DirectoryManager.php b/inc/managers/DirectoryManager.php
index 46f4ef8..c81010d 100644
--- a/inc/managers/DirectoryManager.php
+++ b/inc/managers/DirectoryManager.php
@@ -6,6 +6,7 @@
}
use JVBase\registrar\Registrar;
+use JVBase\base\Site;
use WP_Block;
use WP_Query;
@@ -37,14 +38,14 @@
jvb_register_do_once('buildDirectories', [$this, 'activate']);
add_action('init', [$this, 'registerDirectories']);
- add_action('render_block', [$this, 'renderBlock'], 99999, 3);
+ add_filter('render_block', [$this, 'renderBlock'], 998, 3);
}
public function registerDirectories():void
{
- $singular = (array_key_exists('directory_label', JVB_SITE)) ? JVB_SITE['directory_label'][0] : 'Directory';
- $plural = (array_key_exists('directory_label', JVB_SITE)) ? JVB_SITE['directory_label'][1] : 'Directories';
+ $singular = Site::getDirectorySingular()??'Directory';
+ $plural = Site::getDirectoryPlural()??'Directories';
$config = [
'labels' => [
'name' => $plural,
@@ -130,15 +131,36 @@
}
$config = $registrar->getConfig('directory');
-
$title = $config['title'];
+ //Bail early if we've already created the page
+ $existing = new WP_Query([
+ 'post_type' => BASE.'dash',
+ 'name' => sanitize_title($title),
+ 'posts_per_page' => 1,
+ ]);
+ if ($existing->have_posts()) {
+ $existing = $existing->posts[0];
+ $created[$directory] = $existing->ID;
+ $directories[$directory] = [
+ 'slug' => $existing->post_name,
+ 'title' => $existing->post_title,
+ 'ID' => $existing->ID,
+ 'url' => get_the_permalink($existing->ID),
+ 'page' => $existing->post_title,
+ 'description'=> $existing->post_excerpt,
+ 'type' => $type,
+ 'extra' => $config[$directory]['directory_extra']??[],
+ ];
+ continue;
+ }
+
$excerpt = implode(' ', $config['description']??[]);
$ID = wp_insert_post([
'post_type' => BASE.'directory',
'post_title' => $title,
'post_status' => 'publish',
'post_excerpt' => $excerpt,
- 'slug' => sanitize_title($title)
+ 'post_name' => sanitize_title($title)
]);
if (!is_wp_error($ID)) {
add_post_meta($ID, self::$type, $type);
@@ -186,7 +208,7 @@
}
}
-// if (Features::forSite()->has('has_map')) {
+// if (Site::has('has_map')) {
// $ID = wp_insert_post([
// 'post_type' => BASE.'directory',
// 'post_title' => 'Map',
@@ -351,7 +373,7 @@
$config = Registrar::getInstance($slug);
$aOpen = '<a href="'.$directory['url'].'" title="See our list of '.$directory['title'].'">';
$aClose = '</a>';
- $cache .= '<li class="directory col start">
+ $cache .= '<li class="directory col left">
'. $aOpen.jvbIcon($config->getIcon() !== '' ? $config->getIcon() :'list-dashes').$directory['title'].$aClose;
if (!empty($directory['description'])) {
$cache .= '<div class="description">';
@@ -390,7 +412,7 @@
);
if ($current !== '' && array_key_exists($current, $this->directories())) {
$open = ($open) ? ' open' : '';
- $cache = '<details'.$open.'><summary class="row btw">Other '.$this->referAs(true).':</summary>'.
+ $cache = '<details'.$open.'><summary class="row x-btw">Other '.$this->referAs(true).':</summary>'.
str_replace('id="'.$current.'"', 'id="'.$current.'" class="current"', $cache)
.'</details>';
}
@@ -591,7 +613,7 @@
$children =$this->renderListChunk($taxonomy, $term->term_id);
$out .= '<li>';
if ($children !== '') {
- $out .= '<details class="term"><summary class="row btw"><a href="'.get_term_link($term->term_id, $term->taxonomy).'" title="See more '.html_entity_decode($term->name).'">'.$term->name.'</a></summary>';
+ $out .= '<details class="term"><summary class="row x-btw"><a href="'.get_term_link($term->term_id, $term->taxonomy).'" title="See more '.html_entity_decode($term->name).'">'.$term->name.'</a></summary>';
$out .= $children;
$out .= '</details>';
} else {
@@ -646,7 +668,7 @@
$out = '<ul class="list-none">';
foreach ($list as $letter => $items) {
- $out .= '<li id="starts-with-'.$letter.'" class="row a-start btw nowrap"><h3>'.strtoupper($letter).'</h3><ul>';
+ $out .= '<li id="starts-with-'.$letter.'" class="row top x-btw nowrap"><h3>'.strtoupper($letter).'</h3><ul>';
foreach ($items as $item) {
$extra = '';
if (!empty($item['extra'])) {
@@ -661,7 +683,7 @@
$item_html = apply_filters('jvb_directory_render_item', '', $item, $type, $extra);
if (empty($item_html)) {
- $item_html = '<li class="row btw">
+ $item_html = '<li class="row x-btw">
<a href="'.$item['url'].'" title="More about '.$item['name'].'">
'.$item['name'].'</a>'.$extra.'
</li>';
@@ -684,6 +706,7 @@
return $content;
}
+ error_log('Still working on directory manager...');
// For archive page
if (is_post_type_archive(BASE.'directory') && $block['blockName'] === 'core/group') {
return ($block['attrs']['tagName']??'' === 'main') ? '<main>'.$this->renderArchive().'</main>' : $content;
@@ -710,10 +733,7 @@
public function referAs($plural = false):string
{
- if (!empty(JVB_SITE) && array_key_exists('directory_label', JVB_SITE)) {
- return ($plural) ? JVB_SITE['directory_label'][1] : JVB_SITE['directory_label'][0];
- }
- return ($plural) ? 'Directories' : 'Directory';
+ return ($plural) ? Site::getDirectoryPlural()??'Directories' : Site::getDirectorySingular()??'Directory';
}
/*****************************************************
--
Gitblit v1.10.0