From d7e7d248cbe41cd7a9ef9c2fb022b6c4831f99a3 Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Sun, 31 May 2026 15:22:56 +0000
Subject: [PATCH] =jakevan complete
---
inc/registrar/fields/Field.php | 79 +++++++++++++++++++++++++++++++--------
1 files changed, 63 insertions(+), 16 deletions(-)
diff --git a/inc/registrar/fields/Field.php b/inc/registrar/fields/Field.php
index e34c80e..c1d5e33 100644
--- a/inc/registrar/fields/Field.php
+++ b/inc/registrar/fields/Field.php
@@ -19,6 +19,11 @@
protected bool $quickEdit = true; // whether to show in quick edit table
protected bool $quill; // whether to use quill
protected int $maxLength; // of characters
+ protected int $min;
+ protected int $max;
+ protected string $subtype;
+ protected array $condition;
+ protected array $allowedSubtype = ['text', 'url','number','tel','email','number'];
/**
* @var ?bool For timeline post types. Indicates whether all posts get this field, or just the parent
*/
@@ -50,10 +55,10 @@
foreach ($config as $key => $value) {
if (property_exists($class, $key)) {
- $method = 'set' . ucfirst($key);
+ $method = 'set'.implode('',array_map('ucfirst',explode('_', $key)));;
$class->$method($value);
} else {
- error_log('Instance: '.print_r($class, true));
+// error_log('Instance: '.print_r($class, true));
error_log('[JVBase\registrar\Field] Invalid key for '.$name.': '.$key);
}
}
@@ -76,7 +81,7 @@
return $this->hint;
}
- protected function setType(string $type):void{
+ public function setType(string $type):void{
$allowed = array_keys(MetaTypeManager::getTypes());
if (!in_array($type, $allowed)) {
error_log('[JVBase\registrar\Field] Invalid type attempted '.$type);
@@ -85,24 +90,24 @@
$this->type = $type;
}
- protected function setLabel(string $label):void{
+ public function setLabel(string $label):void{
$this->label = $label;
}
- protected function setRequired(bool $required):void{
+ public function setRequired(bool $required):void{
$this->required = $required;
}
- protected function setHidden(bool $hidden):void{
+ public function setHidden(bool $hidden):void{
$this->hidden = $hidden;
}
- protected function setQuickEdit(bool $quickEdit):void{
+ public function setQuickEdit(bool $quickEdit):void{
$this->quickEdit = $quickEdit;
}
- protected function setDefault(mixed $default):void
+ public function setDefault(mixed $default):void
{
$this->default = $default;
}
- protected function setQuill(bool $quill):void
+ public function setQuill(bool $quill):void
{
$this->quill = $quill;
}
@@ -123,24 +128,39 @@
{
return $this->section??null;
}
-
- protected function setMaxLength(int $maxLength):void
+ public function setMin(int $min):void
+ {
+ $this->min = $min;
+ }
+ public function getMin():?int
+ {
+ return $this->min??null;
+ }
+ public function setMax(int $max):void
+ {
+ $this->max = $max;
+ }
+ public function getMax():?int
+ {
+ return $this->max??null;
+ }
+ public function setMaxLength(int $maxLength):void
{
$this->maxLength = $maxLength;
}
public function getConfig():array{
$config = get_object_vars($this);
- $config = array_map(function ($item) {
+ return array_map(function ($item) {
if (is_a($item, Field::class)) {
return $item->getConfig();
} else if (is_array($item)) {
$temp = [];
- foreach ($item as $v) {
+ foreach ($item as $k => $v) {
if (is_a($v, Field::class)) {
- $temp[] = $v->getConfig();
+ $temp[$k] = $v->getConfig();
} else {
- $temp[] = $v;
+ $temp[$k] = $v;
}
}
return $temp;
@@ -148,7 +168,34 @@
return $item;
}
}, $config);
+ }
+ public function setSubtype(string $subtype):void
+ {
+ if (!in_array($subtype, $this->allowedSubtype)) {
+ error_log('[SelectorField]Attempted subtype not allowed: '.$subtype);
+ return;
+ }
+ $this->subtype = $subtype;
+ }
+ public function getSubtype():string
+ {
+ return $this->subtype;
+ }
- return $config;
+ public function setCondition(array $condition):void
+ {
+ $required = ['field', 'operator', 'value'];
+ foreach ($required as $field) {
+ if (!array_key_exists($field, $condition)) {
+ error_log('[Field]::setCondition Required condition '.$field.' not found');
+ return;
+ }
+ }
+
+ $this->condition = $condition;
+ }
+ public function getCondition(array $condition):array
+ {
+ return $this->condition;
}
}
--
Gitblit v1.10.0