Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 43 additions & 11 deletions modules/backend/classes/FormField.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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);

Expand All @@ -281,18 +286,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) {
Expand Down Expand Up @@ -729,4 +734,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;
}
Comment on lines +742 to +751
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

TypeError when $this->config is null.

array_key_exists() throws a TypeError in PHP 8+ if the second argument is null. Since $config is not initialized in the constructor and only set when displayAs() is called, accessing dynamic properties on a field that hasn't been fully configured will crash.

🐛 Proposed fix
 public function __get($name)
 {
-    if (array_key_exists($name, $this->config)) {
+    if (is_array($this->config) && array_key_exists($name, $this->config)) {
         return array_get($this->config, $name);
     }
     if (property_exists($this, $name)) {
         return $this->{$name};
     }
     return null;
 }
🤖 Prompt for AI Agents
In `@modules/backend/classes/FormField.php` around lines 742 - 751, The __get
magic method can call array_key_exists($name, $this->config) when $this->config
is null causing a TypeError; make this null-safe by first ensuring $this->config
is an array (either initialize $this->config = [] in the constructor or coerce
before checking) and replace the existing check with something like if
(is_array($this->config) && array_key_exists($name, $this->config)) or use
$config = (array)$this->config and then array_key_exists($name, $config); keep
the subsequent array_get($this->config, $name) consistent with the chosen
approach so you don’t pass null into array helpers.


/**
* 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});
}
Comment on lines +757 to +763
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Same null-safety issue in __isset().

This method has the same TypeError risk when $this->config is null.

🐛 Proposed fix
 public function __isset($name)
 {
-    if (array_key_exists($name, $this->config)) {
+    if (is_array($this->config) && array_key_exists($name, $this->config)) {
         return true;
     }
     return property_exists($this, $name) && !is_null($this->{$name});
 }
🤖 Prompt for AI Agents
In `@modules/backend/classes/FormField.php` around lines 757 - 763, The __isset
method can throw a TypeError if $this->config is null because array_key_exists
expects an array; update the check to first ensure $this->config is an array
(e.g., use is_array($this->config) && array_key_exists($name, $this->config))
before calling array_key_exists, keeping the existing fallback to
property_exists($this, $name) && !is_null($this->{$name}) to preserve behavior.

}
15 changes: 6 additions & 9 deletions modules/backend/widgets/form/partials/_field_url.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,15 @@ class="form-control"
name="<?= $field->getName() ?>"
id="<?= $field->getId() ?>"
value="<?= e($field->value) ?>"
placeholder="<?= e(trans($field->placeholder)) ?>"
class="form-control"
<?= isset($field->autocomplete) && is_string($field->autocomplete) ? 'autocomplete="' . e($field->autocomplete) . '"' : '' ?>
<?= isset($field->maxlength) && is_numeric($field->maxlength) ? 'maxlength="' . e($field->maxlength) . '"' : '' ?>
<?= isset($field->minlength) && is_numeric($field->minlength) ? 'minlength="' . e($field->minlength) . '"' : '' ?>
<?= isset($field->pattern) && is_string($field->pattern) ? 'pattern="' . e($field->pattern) . '"' : '' ?>
<?= isset($field->placeholder) && is_string($field->placeholder) ? 'placeholder="' . e($field->placeholder) . '"' : '' ?>
<?= isset($field->size) && is_numeric($field->size) ? 'size="' . e($field->size) . '"' : '' ?>
<?= $field->getAttributes() ?>
<?= isset($field->maxlength) ? 'maxlength="' . e($field->maxlength) . '"' : '' ?>
<?= isset($field->minlength) ? 'minlength="' . e($field->minlength) . '"' : '' ?>
<?= isset($field->pattern) ? 'pattern="' . e($field->pattern) . '"' : '' ?>
<?= isset($field->size) ? 'size="' . e($field->size) . '"' : '' ?>
<?= $listId ? 'list="' . e($listId) . '"' : '' ?>
<?= isset($field->autocomplete) ? 'autocomplete="' . e($field->autocomplete) . '"' : '' ?>
<?= isset($field->required) && $field->required ? 'required' : '' ?>
<?= isset($field->readonly) && $field->readonly ? 'readonly' : '' ?>
<?= isset($field->disabled) && $field->disabled ? 'disabled' : '' ?>
/>
<?php if ($hasOptions): ?>
<datalist id="<?= e($listId) ?>">
Expand Down
Loading