From 90ac018f0ebf301d47cd1d6aff0c197a2da01aa3 Mon Sep 17 00:00:00 2001 From: Marc Jauvin Date: Wed, 14 Jan 2026 14:39:55 -0500 Subject: [PATCH 1/4] add magic methods to allow dynamic field configs --- modules/backend/classes/FormField.php | 43 ++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 8 deletions(-) diff --git a/modules/backend/classes/FormField.php b/modules/backend/classes/FormField.php index 1f63e72ec8..2310eb729d 100644 --- a/modules/backend/classes/FormField.php +++ b/modules/backend/classes/FormField.php @@ -281,18 +281,18 @@ protected function evalConfig($config) */ $applyConfigValues = [ 'commentHtml', - 'placeholder', + 'context', + 'cssClass', 'dependsOn', - 'required', - 'readOnly', 'disabled', - 'cssClass', - 'stretch', - 'context', 'hidden', - 'trigger', - 'preset', 'path', + 'placeholder', + 'preset', + 'readOnly', + 'required', + 'stretch', + 'trigger', ]; foreach ($applyConfigValues as $value) { @@ -729,4 +729,31 @@ protected function getFieldNameFromData($fieldName, $data, $default = null) return $result; } + + /** + * Implements the getter functionality. + * @param string $name + */ + public function __get($name) + { + if (array_key_exists($name, $this->config)) { + return array_get($this->config, $name); + } + if (property_exists($this, $name)) { + return $this->{$name}; + } + return null; + } + + /** + * Determine if an attribute exists on the object. + * @param string $name + */ + public function __isset($name) + { + if (array_key_exists($name, $this->config)) { + return true; + } + return property_exists($this, $name) && !is_null($this->{$name}); + } } From 0b94f8115aeeabea102426239758f74c0f3f1368 Mon Sep 17 00:00:00 2001 From: Marc Jauvin Date: Wed, 14 Jan 2026 15:12:47 -0500 Subject: [PATCH 2/4] do not set $size="large" for all fields --- modules/backend/classes/FormField.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/modules/backend/classes/FormField.php b/modules/backend/classes/FormField.php index 2310eb729d..f5125088d0 100644 --- a/modules/backend/classes/FormField.php +++ b/modules/backend/classes/FormField.php @@ -91,9 +91,9 @@ class FormField public $span = 'full'; /** - * @var string Specifies a size. Possible values: tiny, small, large, huge, giant. + * @var string|int Specifies a size. Possible values for textarea: tiny, small, large, huge, giant. */ - public $size = 'large'; + public $size; /** * @var string Specifies contextual visibility of this form field. @@ -211,7 +211,7 @@ public function span($value = 'full') } /** - * Sets a side of the field on a form. + * Sets the size of the field on a form. * @param string $value Specifies a size. Possible values: tiny, small, large, huge, giant */ public function size($value = 'large') @@ -259,6 +259,11 @@ public function options($value = null) */ public function displayAs($type, $config = []) { + if (in_array($type, ['textarea', 'widget'])) { + // defaults to 'large' + $this->size = 'large'; + } + $this->type = strtolower($type) ?: $this->type; $this->config = $this->evalConfig($config); From 6c2773eb97c9e123c9030fc19bd5f7cead9a7535 Mon Sep 17 00:00:00 2001 From: Marc Jauvin Date: Wed, 14 Jan 2026 15:24:35 -0500 Subject: [PATCH 3/4] remove attributes already set by FormField getAttributes() --- modules/backend/widgets/form/partials/_field_url.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/modules/backend/widgets/form/partials/_field_url.php b/modules/backend/widgets/form/partials/_field_url.php index 2144ecbc62..d2f344a83f 100644 --- a/modules/backend/widgets/form/partials/_field_url.php +++ b/modules/backend/widgets/form/partials/_field_url.php @@ -30,15 +30,12 @@ class="form-control" placeholder="placeholder)) ?>" class="form-control" getAttributes() ?> + autocomplete) ? 'autocomplete="' . e($field->autocomplete) . '"' : '' ?> maxlength) ? 'maxlength="' . e($field->maxlength) . '"' : '' ?> minlength) ? 'minlength="' . e($field->minlength) . '"' : '' ?> pattern) ? 'pattern="' . e($field->pattern) . '"' : '' ?> - size) ? 'size="' . e($field->size) . '"' : '' ?> + size) && is_numeric($field->size) ? 'size="' . e($field->size) . '"' : '' ?> - autocomplete) ? 'autocomplete="' . e($field->autocomplete) . '"' : '' ?> - required) && $field->required ? 'required' : '' ?> - readonly) && $field->readonly ? 'readonly' : '' ?> - disabled) && $field->disabled ? 'disabled' : '' ?> /> From a85b087814b8e200d81ee8258a952ff000766609 Mon Sep 17 00:00:00 2001 From: Marc Jauvin Date: Wed, 14 Jan 2026 16:24:16 -0500 Subject: [PATCH 4/4] be more strict before adding attributes --- modules/backend/widgets/form/partials/_field_url.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/backend/widgets/form/partials/_field_url.php b/modules/backend/widgets/form/partials/_field_url.php index d2f344a83f..43b68e7e3d 100644 --- a/modules/backend/widgets/form/partials/_field_url.php +++ b/modules/backend/widgets/form/partials/_field_url.php @@ -27,14 +27,14 @@ class="form-control" name="getName() ?>" id="getId() ?>" value="value) ?>" - placeholder="placeholder)) ?>" class="form-control" - getAttributes() ?> - autocomplete) ? 'autocomplete="' . e($field->autocomplete) . '"' : '' ?> - maxlength) ? 'maxlength="' . e($field->maxlength) . '"' : '' ?> - minlength) ? 'minlength="' . e($field->minlength) . '"' : '' ?> - pattern) ? 'pattern="' . e($field->pattern) . '"' : '' ?> + autocomplete) && is_string($field->autocomplete) ? 'autocomplete="' . e($field->autocomplete) . '"' : '' ?> + maxlength) && is_numeric($field->maxlength) ? 'maxlength="' . e($field->maxlength) . '"' : '' ?> + minlength) && is_numeric($field->minlength) ? 'minlength="' . e($field->minlength) . '"' : '' ?> + pattern) && is_string($field->pattern) ? 'pattern="' . e($field->pattern) . '"' : '' ?> + placeholder) && is_string($field->placeholder) ? 'placeholder="' . e($field->placeholder) . '"' : '' ?> size) && is_numeric($field->size) ? 'size="' . e($field->size) . '"' : '' ?> + getAttributes() ?> />