Skip to content

Conversation

ManukMinasyan
Copy link
Collaborator

No description provided.

…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.
@Copilot Copilot AI review requested due to automatic review settings October 8, 2025 17:17
@ManukMinasyan ManukMinasyan merged commit c46ddf6 into 2.x Oct 8, 2025
Copy link

@Copilot Copilot AI left a 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;
Copy link

Copilot AI Oct 8, 2025

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>
Copy link

Copilot AI Oct 8, 2025

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.

Comment on lines +40 to 41
public function values(null|(Model&HasCustomFields) $model = null): Collection
{
Copy link

Copilot AI Oct 8, 2025

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.

Suggested change
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.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant