Skip to content

Conversation

@mjauvin
Copy link
Member

@mjauvin mjauvin commented Jan 14, 2026

FormField now accepts new attributes dynamically.

Summary by CodeRabbit

  • Improvements

    • Textarea and widget fields now default to a larger, more usable size.
    • URL inputs accept and respect maxlength, minlength, pattern, placeholder and size attributes for better validation and UX.
  • Bug Fixes

    • Cleaner and more consistent rendering of form attributes, improving autocomplete behavior and attribute handling.

✏️ Tip: You can customize this high-level summary in your review settings.

@mjauvin mjauvin added this to the 1.2.10 milestone Jan 14, 2026
@mjauvin mjauvin requested a review from LukeTowers January 14, 2026 20:27
@mjauvin mjauvin self-assigned this Jan 14, 2026
@mjauvin mjauvin added the maintenance PRs that fix bugs, are translation changes or make only minor changes label Jan 14, 2026
@coderabbitai
Copy link

coderabbitai bot commented Jan 14, 2026

Walkthrough

Removed default from FormField::$size, added magic __get/__isset for config-backed properties, auto-size behavior for textarea/widget in displayAs, and reorganized which config keys are applied. URL field partial now conditionally renders autocomplete, maxlength, minlength, pattern, placeholder, and numeric size; removed required/readonly/disabled rendering.

Changes

Cohort / File(s) Summary
FormField class
modules/backend/classes/FormField.php
Removed default 'large' from public $size (now uninitialized); docblock for $size broadened to `string
Form URL field partial
modules/backend/widgets/form/partials/_field_url.php
Added guarded rendering of autocomplete, maxlength, minlength, pattern, placeholder, and numeric size attributes; placeholder no longer passed through trans(); removed rendering of required, readonly, and disabled attributes and eliminated duplicated secondary attribute block.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Title check ❓ Inconclusive The title 'Fix url form field' is vague and generic, using broad language that doesn't clearly convey what aspect of the url form field is being fixed or what the main changes accomplish. Consider a more specific title that describes the key change, such as 'Add dynamic attribute support to FormField' or 'Improve url field attribute handling with magic methods'.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings


📜 Recent review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6c2773e and a85b087.

📒 Files selected for processing (1)
  • modules/backend/widgets/form/partials/_field_url.php
🚧 Files skipped from review as they are similar to previous changes (1)
  • modules/backend/widgets/form/partials/_field_url.php
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (9)
  • GitHub Check: ubuntu-latest / PHP 8.1
  • GitHub Check: windows-latest / PHP 8.3
  • GitHub Check: ubuntu-latest / PHP 8.4
  • GitHub Check: ubuntu-latest / PHP 8.2
  • GitHub Check: windows-latest / PHP 8.4
  • GitHub Check: windows-latest / PHP 8.1
  • GitHub Check: windows-latest / PHP 8.2
  • GitHub Check: ubuntu-latest / PHP 8.3
  • GitHub Check: windows-latest / JavaScript

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.


Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In `@modules/backend/classes/FormField.php`:
- Around line 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.
- Around line 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.
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 22df8f1 and 6c2773e.

📒 Files selected for processing (2)
  • modules/backend/classes/FormField.php
  • modules/backend/widgets/form/partials/_field_url.php
🧰 Additional context used
🧬 Code graph analysis (1)
modules/backend/widgets/form/partials/_field_url.php (1)
modules/backend/classes/FormField.php (1)
  • size (217-221)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (9)
  • GitHub Check: windows-latest / PHP 8.3
  • GitHub Check: ubuntu-latest / PHP 8.4
  • GitHub Check: ubuntu-latest / PHP 8.3
  • GitHub Check: windows-latest / PHP 8.2
  • GitHub Check: windows-latest / PHP 8.4
  • GitHub Check: windows-latest / PHP 8.1
  • GitHub Check: windows-latest / JavaScript
  • GitHub Check: ubuntu-latest / PHP 8.1
  • GitHub Check: ubuntu-latest / PHP 8.2
🔇 Additional comments (5)
modules/backend/classes/FormField.php (3)

94-96: LGTM - Size property no longer has a universal default.

Removing the default 'large' value and compensating in displayAs() for textarea/widget types is a sensible approach. This allows other field types to have no size unless explicitly configured.


262-266: LGTM - Appropriate default for textarea and widget types.

Setting size = 'large' before the type is assigned ensures textarea and widget fields maintain their expected sizing behavior after removing the property-level default.


289-300: LGTM - Config keys reorganized.

The expanded list of auto-applied config values (context, cssClass, placeholder, preset, readOnly, required, stretch, trigger) centralizes configuration handling appropriately.

modules/backend/widgets/form/partials/_field_url.php (2)

33-33: LGTM - Autocomplete attribute properly rendered.

Leveraging isset($field->autocomplete) (via the new __isset magic method) to conditionally render the autocomplete attribute is the right approach.


37-37: LGTM - Size attribute restricted to numeric values.

The HTML size attribute expects a numeric value, while FormField::$size can hold string descriptors like 'large' or 'small' for CSS purposes. This check correctly prevents invalid HTML attributes.

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.

Comment on lines +742 to +751
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;
}
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.

Comment on lines +757 to +763
public function __isset($name)
{
if (array_key_exists($name, $this->config)) {
return true;
}
return property_exists($this, $name) && !is_null($this->{$name});
}
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintenance PRs that fix bugs, are translation changes or make only minor changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants