-
Notifications
You must be signed in to change notification settings - Fork 16
Feature/auto detect model context #44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…lders Add smart auto-detection that allows CustomFields form and infolist builders to work without explicit forModel()/forSchema() calls by detecting context from Filament component hierarchy. Changes: - Add FormContainer component with deferred schema generation - Update InfolistContainer to use inline priority resolution - Add explicitModel tracking in BaseBuilder - Implement priority system: explicit > auto-detect > fallback - Use inline priority pattern (KISS): explicitModel ?? getRecord() ?? getModel() All builders now support three usage patterns: 1. Auto-detection: CustomFields::form()->build() 2. Explicit model: CustomFields::form()->forModel(Post::class)->build() 3. Explicit schema: CustomFields::form()->forSchema($schema)->build() Priority resolution ensures explicit parameters always take precedence over auto-detection. Graceful fallback returns empty array when no context available. Zero breaking changes - all existing usage patterns continue to work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces automatic model context detection for Filament integration builders, enabling dynamic schema generation based on the runtime context when explicit models aren't provided.
- Adds new container classes (InfolistContainer and FormContainer) that defer schema generation and auto-detect models
- Updates existing builders to use the new containers instead of static Grid components
- Implements a model resolution hierarchy: explicit model → record → model class
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
File | Description |
---|---|
src/Filament/Integration/Builders/InfolistContainer.php | New container class for infolists with deferred schema generation and model auto-detection |
src/Filament/Integration/Builders/InfolistBuilder.php | Updated to use InfolistContainer and support optional model parameter in values() method |
src/Filament/Integration/Builders/FormContainer.php | New container class for forms with deferred schema generation and model auto-detection |
src/Filament/Integration/Builders/FormBuilder.php | Updated to use FormContainer instead of static Grid |
src/Filament/Integration/Builders/BaseBuilder.php | Added explicitModel property to track explicitly set models |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
|
||
namespace Relaticle\CustomFields\Filament\Integration\Builders; | ||
|
||
use Filament\Forms\Components\Field; |
Copilot
AI
Oct 8, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This import appears to be incorrect for an infolist component. InfolistContainer should import Entry components from Filament\Infolists\Components\Entry instead of Field from Forms.
Copilot uses AI. Check for mistakes.
} | ||
|
||
/** | ||
* @return array<int, Field> |
Copilot
AI
Oct 8, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The return type annotation is incorrect. Since this is for infolists, it should return array<int, Entry> instead of array<int, Field>.
Copilot uses AI. Check for mistakes.
public function values(null|(Model&HasCustomFields) $model = null): Collection | ||
{ |
Copilot
AI
Oct 8, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding an optional parameter to an existing public method changes the API signature. This could be a breaking change if other code expects the original signature. Consider creating a separate method or ensuring backward compatibility.
public function values(null|(Model&HasCustomFields) $model = null): Collection | |
{ | |
/** | |
* @return Collection<int, mixed> | |
*/ | |
public function values(): Collection | |
{ | |
return $this->valuesForModel(null); | |
} | |
/** | |
* @param null|(Model&HasCustomFields) $model | |
* @return Collection<int, mixed> | |
*/ | |
public function valuesForModel(null|(Model&HasCustomFields) $model = null): Collection | |
{ |
Copilot uses AI. Check for mistakes.
No description provided.