From ba1e1ccf869b818f7a7a897264dfea05563a7796 Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Sun, 07 Jun 2026 20:10:20 +0000
Subject: [PATCH] =Major overhaul of Integrations. Playing around with adding fields to post types through Registrar from an integrations' class file.

---
 inc/registrar/Fields.php |  287 +++++++++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 255 insertions(+), 32 deletions(-)

diff --git a/inc/registrar/Fields.php b/inc/registrar/Fields.php
index 47f9f55..5635c0c 100644
--- a/inc/registrar/Fields.php
+++ b/inc/registrar/Fields.php
@@ -1,11 +1,15 @@
 <?php
 namespace JVBase\registrar;
 
+use JVBase\managers\SEO\render\Thing\Organization\LocalBusiness\LocalBusiness;
+use JVBase\managers\SEO\render\Thing\Thing;
 use JVBase\registrar\fields\Field;
 use JVBase\registrar\fields\GroupedField;
 use JVBase\registrar\fields\OptionsField;
-use JVBase\registrar\fields\TaxonomyField;
-use JVBase\registrar\fields\Upload;
+use JVBase\registrar\fields\RepeaterField;
+use JVBase\registrar\fields\TagListField;
+use JVBase\registrar\fields\SelectorField;
+use JVBase\registrar\fields\UploadField;
 
 if (!defined('ABSPATH')) {
 	exit;
@@ -13,9 +17,10 @@
 
 class Fields {
 	protected array $fields;
-	protected Registrar $registrar;
+	private Registrar $registrar;
 
 	public function __construct(?string $type = null, ?Registrar $registrar = null) {
+		$this->registrar = $registrar;
 		switch ($type) {
 			case 'post':
 				$this->addPostFields();
@@ -27,15 +32,16 @@
 				$this->addUserFields();
 				break;
 		}
-		$this->registrar = $registrar;
 	}
 
 	public function addField(string $name, array $config):self {
 		$this->fields[$name] = match ($config['type']) {
-			'upload', 'image', 'gallery' 	=> new Upload($name, $config),
+			'upload', 'image', 'gallery' 	=> new UploadField($name, $config),
 			'checkbox', 'radio', 'select', 'set' => new OptionsField($name, $config),
-			'repeater', 'group', 'tagList' => new GroupedField($name, $config),
-			'selector', 'taxonomy', 'user', 'post' => new TaxonomyField($name, $config),
+			'group' => new GroupedField($name, $config),
+			'repeater'	=> new RepeaterField($name, $config),
+			'tagList'	=> new TagListField($name, $config),
+			'selector', 'taxonomy', 'user', 'post' => new SelectorField($name, $config),
 			default => new Field($name, $config),
 		};
 
@@ -44,9 +50,56 @@
 
 	public function addPostFields():void
 	{
+		$statuses = [
+//					'all' => [
+//						'icon' => 'infinity',
+//						'label' => 'Everything',
+//					],
+			'publish' => [
+				'icon' => 'eye',
+				'label' => 'Live',
+			],
+			'draft' => [
+				'icon' => 'eye-closed',
+				'label' => 'Hidden',
+			],
+			'trash' => [
+				'label' => 'Scrapped',
+				'icon' => 'trash',
+			],
+//			'delete'	=> [
+//				'label'	=> 'Permanently Delete',
+//				'icon'	=> 'trash'
+//			]
+		];
+		if ($this->registrar->hasFeature('is_calendar')) {
+			$statuses = [
+				'future'	=> [
+					'icon'	=> '',
+					'label'	=> 'Upcoming',
+				],
+				'past'	=> [
+					'icon'	=> '',
+					'label'	=> 'Past',
+				],
+				'repeat'	=> [
+					'icon'	=> '',
+					'label'	=> 'Repeating',
+				],
+				'draft' => [
+					'icon' => 'eye-closed',
+					'label' => 'Hidden',
+				],
+				'trash' => [
+					'label' => 'Scrapped',
+					'icon' => 'trash',
+				],
+			];
+		}
 		$fields = [
 			'post_thumbnail'	=> [
 				'type'	=> 'upload',
+				'subtype'	=> 'image',
 				'multiple'=> false,
 				'label'	=> 'Main Image',
 			],
@@ -54,6 +107,11 @@
 				'type'	=> 'datetime',
 				'label'	=> 'Date',
 			],
+			'post_modified' => [
+				'type'	=> 'datetime',
+				'label'	=> 'Date Modified',
+				'hidden'	=> true,
+			],
 			'post_content' => [
 				'type'	=> 'textarea',
 				'quill'	=> true,
@@ -73,28 +131,7 @@
 				'type'		=> 'radio',
 				'label'		=> 'Status',
 				'default'	=> 'draft',
-				'options'	=> [
-					'all' => [
-						'icon' => 'infinity',
-						'label' => 'Everything',
-					],
-					'publish' => [
-						'icon' => 'eye',
-						'label' => 'Live',
-					],
-					'draft' => [
-						'icon' => 'eye-closed',
-						'label' => 'Hidden',
-					],
-					'trash' => [
-						'label' => 'Scrapped',
-						'icon' => 'trash',
-					],
-					'delete'	=> [
-						'label'	=> 'Permanently Delete',
-						'icon'	=> 'trash'
-					]
-				]
+				'options'	=> $statuses
 			]
 		];
 
@@ -117,10 +154,10 @@
 				'label'		=> 'Description',
 			]
 		];
-		if ($this->registrar->registrar->hierarchical){
+		if ($this->registrar->args()['hierarchical']??false){
 			$fields['parent'] = [
 				'type'			=> 'taxonomy',
-				'taxonomy_type'	=> 'reference',
+				'isReference'	=> true,
 				'autocomplete'	=> true,
 				'label'			=> 'Term Parent'
 			];
@@ -162,12 +199,198 @@
 
 	public function  modifyField(string $name, string $property, mixed $value):void
 	{
+		$property = 'set'.implode('',array_map('ucfirst',explode('_', $property)));
 		$field = $this->fields[$name];
-		$field->$property = $value;
+		$field->$property($value);
 	}
 
 	public function getFields():array
 	{
 		return $this->fields;
 	}
+
+	public function addCommon(string $name):self
+	{
+		$method = 'add'.implode('',array_map('ucfirst',explode('_', $name))).'Field';
+		if (method_exists($this, $method)) {
+			$this->$method();
+		} else {
+			error_log('[Field]addCommon: No configuration found for '.$name.'.');
+		}
+		return $this;
+	}
+
+	protected function addWikiField(?string $label = null):void
+	{
+		$this->addField(
+			'wiki',
+			[
+				'type'        => 'url',
+				'label'       => $label ?: 'Wikipedia Page',
+				'description' => 'For the schema',
+				'quickEdit'   => true,
+			]
+		);
+	}
+
+	protected function addLinksField(?string $label = null):void
+	{
+		$this->addField(
+			'links',
+			[
+				'type'        => 'repeater',
+				'quickEdit'   => true,
+				'add_label'	=> 'title',
+				'label'       => $label ?:'Online Links',
+				'description' => 'These are listed publicly on the website',
+				'fields'      => [
+					'url'     => [
+						'type'  => 'url',
+						'label' => 'URL',
+					],
+					'title'   => [
+						'type'  => 'text',
+						'label' => 'Label',
+					],
+					'tracker' => [
+						'type'        => 'text',
+						'label'       => 'Tracker',
+						'description' => 'If you are set up to track link referrals, add what comes after the ? here.',
+						'default'		=> 'ref=edmonton_ink'
+					],
+				],
+				'section'     => 'contact'
+			]
+		);
+	}
+
+	protected function addContactField():void
+	{
+		$this->addField(
+			'admin_contact',
+			[
+				'type'      => 'set',
+				'label'     => 'Admin Contact',
+				'quickEdit' => true,
+				'options'   => [
+					'text'  => 'Text',
+					'call'  => 'Call',
+					'email' => 'Email',
+					'insta' => 'Instagram',
+				],
+				'section'   => 'contact'
+			]
+		);
+		$this->addField(
+			'public_contact',
+			[
+				'type'      => 'set',
+				'label'     => 'Public Contact',
+				'quickEdit' => true,
+				'options'   => [
+					'text'  => 'Text',
+					'call'  => 'Call',
+					'email' => 'Email',
+					'insta' => 'Instagram',
+				],
+				'section'   => 'contact'
+			]
+		);
+	}
+
+	protected function addReviewField(?string $label = null):void
+	{
+		$biz = new LocalBusiness();
+		$biz->setReviewField($this);
+	}
+
+	protected function addAlternateNameField():void
+	{
+		$thing = new Thing();
+		$thing->setAlternateNameField($this);
+	}
+	protected function addKeywordsField():void
+	{
+		$thing = new LocalBusiness();
+		$thing->setKeywordsField($this);
+	}
+
+	protected function addOutsidePhotoField():void
+	{
+		$business = new LocalBusiness();
+		$business->setPhotoField($this);
+	}
+
+	protected function addSloganField():void
+	{
+		$business = new LocalBusiness();
+		$business->setSloganField($this);
+	}
+
+	protected function addPaymentField():void
+	{
+		$business = new LocalBusiness();
+		$business->setPaymentAcceptedField($this);
+	}
+
+	protected function addAmenitiesField():void
+	{
+		$business = new LocalBusiness();
+		$business->setAmenityFeatureField($this);
+	}
+	protected function addCredentialsField():void
+	{
+		$this->addField(
+			'credentials',
+			[
+				'type'	=> 'set',
+				'label'	=> __('Credentials', 'jvb'),
+				'options'=> [
+					'WHMIS 2015' => 'WHMIS 2015',
+					'Tattoo and Piercing Safety Standards' => 'Tattoo and Piercing Safety Standards',
+					'Bloodborne Pathogens and Infection Control' => 'Bloodborne Pathogens and Infection Control',
+					'First Aid Training' => 'First Aid Training',
+				]
+			]
+		);
+	}
+	protected function addPermanentlyCloseField():void
+	{
+		$business = new LocalBusiness();
+		$business->setDissolutionDateField($this);
+	}
+
+	protected function addHoursField():void
+	{
+		$business = new LocalBusiness();
+		$business->setOpeningHoursSpecificationField($this);
+	}
+
+	protected function addRateField():void
+	{
+		$this->addField('rate',
+		[
+			'type'	=> 'text',
+			'subtype'	=> 'number',
+			'label'		=> __('Hourly Rate', 'jvb')
+		]);
+	}
+
+	protected function addAwardsField():void
+	{
+		$business = new LocalBusiness();
+		$business->setAwardField($this);
+	}
+
+	protected function addRatingsField():void
+	{
+		$business = new LocalBusiness();
+		$business->setAggregateRatingField($this);
+	}
+
+	protected function addServicesField():void
+	{
+		$business = new LocalBusiness();
+		$business->setHasOfferCatalogField($this);
+	}
 }

--
Gitblit v1.10.0