Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/Filament/Integration/Builders/BaseBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ abstract class BaseBuilder
{
protected Model&HasCustomFields $model;

protected Model|string|null $explicitModel = null;

protected Builder $sections;

protected array $except = [];
Expand Down Expand Up @@ -52,6 +54,7 @@ public function forModel(Model|string $model): static
}

$this->model = $model;
$this->explicitModel = $model;

$this->sections = CustomFields::newSectionModel()->query()
->forEntityType($model::class)
Expand Down
5 changes: 4 additions & 1 deletion src/Filament/Integration/Builders/FormBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ class FormBuilder extends BaseBuilder
{
public function build(): Grid
{
return Grid::make(1)->schema($this->values()->toArray());
return FormContainer::make()
->forModel($this->explicitModel ?? null)
->only($this->only)
->except($this->except);
}

private function getDependentFieldCodes(Collection $fields): array
Expand Down
65 changes: 65 additions & 0 deletions src/Filament/Integration/Builders/FormContainer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

namespace Relaticle\CustomFields\Filament\Integration\Builders;

use Filament\Schemas\Components\Grid;
use Illuminate\Database\Eloquent\Model;

final class FormContainer extends Grid
{
private Model|string|null $explicitModel = null;

private array $except = [];

private array $only = [];

public static function make(array|int|null $columns = 1): static
{
$container = new self($columns);

// Defer schema generation until component is in container
$container->schema(fn (): array => $container->generateSchema());

return $container;
}

public function forModel(Model|string|null $model): static
{
$this->explicitModel = $model;

return $this;
}

public function except(array $fieldCodes): static
{
$this->except = $fieldCodes;

return $this;
}

public function only(array $fieldCodes): static
{
$this->only = $fieldCodes;

return $this;
}

private function generateSchema(): array
{
// Inline priority: explicit ?? record ?? model class
$model = $this->explicitModel ?? $this->getRecord() ?? $this->getModel();

if ($model === null) {
return []; // Graceful fallback
}

$builder = app(FormBuilder::class);

return $builder
->forModel($model)
->only($this->only)
->except($this->except)
->values()
->toArray();
}
}
17 changes: 14 additions & 3 deletions src/Filament/Integration/Builders/InfolistBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@

use Filament\Infolists\Components\Entry;
use Filament\Schemas\Components\Component;
use Filament\Schemas\Components\Grid;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Collection;
use Relaticle\CustomFields\Filament\Integration\Factories\FieldInfolistsFactory;
use Relaticle\CustomFields\Filament\Integration\Factories\SectionInfolistsFactory;
use Relaticle\CustomFields\Models\Contracts\HasCustomFields;
use Relaticle\CustomFields\Models\CustomField;
use Relaticle\CustomFields\Models\CustomFieldSection;
use Relaticle\CustomFields\Services\Visibility\BackendVisibilityService;
Expand All @@ -24,14 +25,24 @@ final class InfolistBuilder extends BaseBuilder

public function build(): Component
{
return Grid::make(1)->schema($this->values()->toArray());
return InfolistContainer::make()
->forModel($this->explicitModel ?? null)
->hiddenLabels($this->hiddenLabels)
->visibleWhenFilled($this->visibleWhenFilled)
->withoutSections($this->withoutSections)
->only($this->only)
->except($this->except);
}

/**
* @return Collection<int, mixed>
*/
public function values(): Collection
public function values(null|(Model&HasCustomFields) $model = null): Collection
{
Comment on lines +40 to 41
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.

if ($model !== null) {
$this->forModel($model);
}

$fieldInfolistsFactory = app(FieldInfolistsFactory::class);
$sectionInfolistsFactory = app(SectionInfolistsFactory::class);
$backendVisibilityService = app(BackendVisibilityService::class);
Expand Down
97 changes: 97 additions & 0 deletions src/Filament/Integration/Builders/InfolistContainer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<?php

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.

use Filament\Schemas\Components\Grid;
use Illuminate\Database\Eloquent\Model;

final class InfolistContainer extends Grid
{
private Model|string|null $explicitModel = null;

private array $except = [];

private array $only = [];

private bool $hiddenLabels = false;

private bool $visibleWhenFilled = false;

private bool $withoutSections = false;

public static function make(array|int|null $columns = 1): static
{
$container = new self($columns);

// Defer schema generation until component is in container
$container->schema(fn (): array => $container->generateSchema());

return $container;
}

public function forModel(Model|string|null $model): static
{
$this->explicitModel = $model;

return $this;
}

public function except(array $fieldCodes): static
{
$this->except = $fieldCodes;

return $this;
}

public function only(array $fieldCodes): static
{
$this->only = $fieldCodes;

return $this;
}

public function hiddenLabels(bool $hiddenLabels = true): static
{
$this->hiddenLabels = $hiddenLabels;

return $this;
}

public function visibleWhenFilled(bool $visibleWhenFilled = true): static
{
$this->visibleWhenFilled = $visibleWhenFilled;

return $this;
}

public function withoutSections(bool $withoutSections = true): static
{
$this->withoutSections = $withoutSections;

return $this;
}

/**
* @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.

*/
private function generateSchema(): array
{
// Inline priority: explicit ?? record ?? model class
$model = $this->explicitModel ?? $this->getRecord() ?? $this->getModel();

if ($model === null) {
return []; // Graceful fallback
}

$builder = app(InfolistBuilder::class)
->forModel($model)
->only($this->only)
->except($this->except)
->hiddenLabels($this->hiddenLabels)
->visibleWhenFilled($this->visibleWhenFilled)
->withoutSections($this->withoutSections);

return $builder->values()->toArray();
}
}