Skip to content

Conversation

@mjauvin
Copy link
Member

@mjauvin mjauvin commented Jan 8, 2026

Screenshot_20260108-145505 Chrome

@mjauvin mjauvin self-assigned this Jan 8, 2026
@mjauvin mjauvin added the enhancement PRs that implement a new feature or substantial change label Jan 8, 2026
@coderabbitai
Copy link

coderabbitai bot commented Jan 8, 2026

Walkthrough

A new showLabels boolean property is added to the FormField class to control label visibility for checkbox, switch, and section field types. The form widget's label rendering logic is updated to respect this per-field configuration, replacing the previous universal suppression of labels for these types. Form partials and CSS styling are modified accordingly to conditionally render labels and help text.

Changes

Cohort / File(s) Summary
Core Property Addition
modules/backend/classes/FormField.php
Introduces public showLabels property with docblock; extends config processing to include this property via evalConfig method.
Widget Logic
modules/backend/widgets/Form.php
Updates showFieldLabels() method to return field's showLabels property for checkbox/switch/section types instead of always returning false; defaults to false when unset.
Field Rendering
modules/backend/widgets/form/partials/_field_checkbox.php
Conditionally renders label and help text based on showLabels flag; adds CSS class to label and guards comment rendering.
Field Rendering
modules/backend/widgets/form/partials/_field_switch.php
Conditionally renders label based on showLabels flag; hides help/comment block when showLabels is true.
Styling
modules/system/assets/ui/less/form.less
Narrows required-asterisk selector to exclude labels with show-labels class, preventing asterisk rendering when labels are shown.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and accurately describes the main change: enabling conditional label display for checkbox/switch fields above the field, which is the core feature across all modified files.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

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

✨ Finishing touches
  • 📝 Generate docstrings

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: 0

🧹 Nitpick comments (2)
modules/backend/classes/FormField.php (1)

183-186: Update documentation to include 'section' field type and consider adding type hints.

The docblock mentions "checkbox/switch fields" but the implementation in modules/backend/widgets/Form.php (line 1158) also applies this property to 'section' field types. Additionally, consider adding a type hint and explicit default value for better type safety and clarity.

📝 Suggested improvements
 /**
- * @var bool Should the field's label for checkbox/switch fields be displayed above the field.
+ * @var bool|null Should the field's label for checkbox/switch/section fields be displayed above the field.
+ * When true, the label is rendered above the field by the form widget.
+ * When false or null (default), the label is rendered inline by the field partial.
  */
-public $showLabels;
+public $showLabels = null;
modules/backend/widgets/form/partials/_field_checkbox.php (1)

18-22: Consider accessibility implications of dual label elements.

When showLabels is true, there are effectively two <label> elements associated with the same input:

  1. A label with text content rendered above the field by the form widget
  2. An empty label element here (with show-labels class)

While this maintains the HTML structure, having two labels for one input may have semantic implications. Consider verifying that screen readers handle this correctly and whether ARIA attributes might improve clarity.

If you'd like to verify the accessibility of this implementation, consider testing with screen readers (NVDA, JAWS, VoiceOver) to ensure the dual-label structure doesn't cause confusion.

📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8a7f74b and b1fbb6b.

📒 Files selected for processing (6)
  • modules/backend/classes/FormField.php
  • modules/backend/widgets/Form.php
  • modules/backend/widgets/form/partials/_field_checkbox.php
  • modules/backend/widgets/form/partials/_field_switch.php
  • modules/system/assets/ui/less/form.less
  • modules/system/assets/ui/storm.css
🧰 Additional context used
🧬 Code graph analysis (2)
modules/backend/widgets/form/partials/_field_checkbox.php (1)
modules/backend/classes/FormField.php (2)
  • getId (604-622)
  • comment (361-371)
modules/backend/widgets/form/partials/_field_switch.php (1)
modules/backend/classes/FormField.php (2)
  • getId (604-622)
  • comment (361-371)
⏰ 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.4
  • GitHub Check: ubuntu-latest / PHP 8.4
  • GitHub Check: ubuntu-latest / PHP 8.1
  • GitHub Check: ubuntu-latest / PHP 8.2
  • GitHub Check: windows-latest / PHP 8.3
  • GitHub Check: windows-latest / PHP 8.2
  • GitHub Check: windows-latest / PHP 8.1
  • GitHub Check: ubuntu-latest / PHP 8.3
  • GitHub Check: windows-latest / JavaScript
🔇 Additional comments (5)
modules/backend/classes/FormField.php (1)

287-302: LGTM: showLabels properly integrated into config processing.

The addition of showLabels to the evalConfig array correctly enables this property to be set via field configuration, maintaining consistency with other form field properties.

modules/system/assets/ui/less/form.less (1)

125-139: LGTM: CSS correctly excludes required asterisk for labels in label-above mode.

The :not(.show-labels) selector appropriately prevents the required asterisk from appearing on the inline label element when showLabels is true. In this mode, the asterisk appears on the label rendered above by the form widget, and the inline label element is empty and should not display an asterisk.

modules/backend/widgets/form/partials/_field_checkbox.php (1)

24-26: LGTM: Help text rendering logic is consistent.

The conditional rendering of help text matches the pattern used in the switch partial, correctly showing help text only when labels are rendered inline (showLabels is false).

modules/backend/widgets/Form.php (1)

1156-1167: LGTM: Per-field label visibility control implemented correctly.

The change from return false; to return $field->showLabels ?? false; enables per-field configuration while maintaining backward compatibility. The null coalescing operator ensures existing forms continue to work with the default inline label behavior.

The implementation correctly:

  • Applies to checkbox, switch, and section field types
  • Preserves widget field behavior (which has its own showLabels property)
  • Defaults to false when showLabels is not explicitly set
  • Integrates with the FormField.showLabels property and partial rendering logic
modules/backend/widgets/form/partials/_field_switch.php (1)

14-19: Code logic is correct and properly integrated with the form widget.

The conditional rendering in this partial correctly hides the label and help text when showLabels is false. When showLabels is true, the main form widget partial (_field.php) takes over and uses the commentPosition property to render help text either above or below the field, ensuring help text is never lost.

@mjauvin mjauvin requested a review from LukeTowers January 8, 2026 20:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement PRs that implement a new feature or substantial change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants