[6.x] Add fluent field layout APIs#19247
Open
riasvdv wants to merge 4 commits into
Open
Conversation
📚 Storybook previews@craftcms/cp — open Storybook No changed components detected in this Storybook. resources/js — open Storybook No changed components detected in this Storybook. |
Contributor
There was a problem hiding this comment.
Pull request overview
Adds fluent/builder-style APIs to FieldLayout, FieldLayoutTab, and several layout elements to make programmatic layout composition (and later Inertia/Vue rendering) more ergonomic for core and plugin developers.
Changes:
- Introduced fluent APIs for creating/modifying layouts (
FieldLayout::create(),FieldLayout::tab(),FieldLayoutTab::add(), etc.). - Added fluent configuration helpers on layout elements/components (e.g.
CustomField::for(),FieldLayoutElement::width(), UI element constructors, and condition setters). - Updated/added test coverage and modernized factories/tests to use the fluent APIs; updated BaseField internals and changelog for the new method signatures/renames.
Reviewed changes
Copilot reviewed 17 out of 17 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/Unit/FieldLayout/FluentBuilderTest.php | Adds unit coverage for fluent layout/tab/element APIs and related behaviors (UIDs, cache invalidation, duplicate handling). |
| tests/Feature/FieldLayout/FluentBuilderTest.php | Adds feature coverage for resolving fields by handle and persisting fluent layout modifications. |
| tests/Feature/Field/FieldsTest.php | Updates existing feature tests to build layouts via the new fluent APIs. |
| src/FieldLayout/LayoutElements/Users/EmailField.php | Updates override to renamed protected BaseField method (warningText). |
| src/FieldLayout/LayoutElements/Users/AffiliatedSiteField.php | Updates override to renamed protected BaseField method (instructionsText). |
| src/FieldLayout/LayoutElements/Tip.php | Adds string-friendly constructor and fluent setters for dismissible/style. |
| src/FieldLayout/LayoutElements/Template.php | Adds string-friendly constructor and fluent setter for template mode. |
| src/FieldLayout/LayoutElements/Markdown.php | Adds string-friendly constructor and fluent setter for displayInPane. |
| src/FieldLayout/LayoutElements/Heading.php | Adds string-friendly constructor for heading text. |
| src/FieldLayout/LayoutElements/CustomField.php | Adds CustomField::for() plus fluent mutators that keep field overrides in sync. |
| src/FieldLayout/LayoutElements/BaseField.php | Renames protected text methods, adds fluent setters (label/instructions/tip/warning/required/etc.). |
| src/FieldLayout/FieldLayoutTab.php | Adds add() fluent API with duplicate-field protections and dateAdded initialization. |
| src/FieldLayout/FieldLayoutElement.php | Adds fluent width() setter. |
| src/FieldLayout/FieldLayoutComponent.php | Adds fluent condition setters (userCondition(), elementCondition()). |
| src/FieldLayout/FieldLayout.php | Adds fluent layout creation/modification/removal APIs (create(), tab(), getTab(), removeField(), removeTab()). |
| database/Factories/FieldLayoutFactory.php | Updates factory helpers to build config via the fluent layout APIs. |
| CHANGELOG.md | Documents the new fluent APIs and the BaseField signature/method-name changes. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds fluent APIs for creating and modifying field layouts, tabs, and layout elements.
Before:
After:
or
Once #19248 is stable or merged, I'll take another look at both so we have consistent APIs for creating these kind of fluent components/classes.