From 515cd83d34b7706742d0cc11fc3d390bfc39f0de Mon Sep 17 00:00:00 2001 From: Mathieu Date: Tue, 24 Jun 2025 11:51:57 +0200 Subject: [PATCH] Initial filament v4 --- composer.json | 6 +++--- src/SelectTree.php | 32 ++++++++++++++++---------------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/composer.json b/composer.json index 78c53f8..42807ce 100644 --- a/composer.json +++ b/composer.json @@ -21,13 +21,13 @@ } ], "require": { - "php": "^8.1", + "php": "^8.2", "filament/forms": "^3.0", "spatie/laravel-package-tools": "^1.15.0", "illuminate/contracts": "^10.0|^11.0|^12.0" }, "require-dev": { - "nunomaduro/collision": "^7.9", + "nunomaduro/collision": "^7.9||^8.0", "orchestra/testbench": "^8.0|^9.0|^10.0", "pestphp/pest": "^2.0|^3.7", "pestphp/pest-plugin-arch": "^2.0|^3.0", @@ -62,6 +62,6 @@ ] } }, - "minimum-stability": "dev", + "minimum-stability": "beta", "prefer-stable": true } diff --git a/src/SelectTree.php b/src/SelectTree.php index 1985283..0217c77 100644 --- a/src/SelectTree.php +++ b/src/SelectTree.php @@ -2,19 +2,19 @@ namespace CodeWithDennis\FilamentSelectTree; +use Filament\Schemas\Components\Contracts\HasAffixActions; +use Filament\Schemas\Components\Concerns\CanBeDisabled; +use Filament\Schemas\Components\Concerns\HasActions; +use Filament\Schemas\Schema; +use Filament\Actions\Action; +use InvalidArgumentException; use Closure; use Exception; -use Filament\Forms\ComponentContainer; -use Filament\Forms\Components\Actions\Action; -use Filament\Forms\Components\Concerns\CanBeDisabled; use Filament\Forms\Components\Concerns\CanBeSearchable; -use Filament\Forms\Components\Concerns\HasActions; use Filament\Forms\Components\Concerns\HasAffixes; use Filament\Forms\Components\Concerns\HasPivotData; use Filament\Forms\Components\Concerns\HasPlaceholder; -use Filament\Forms\Components\Contracts\HasAffixActions; use Filament\Forms\Components\Field; -use Filament\Forms\Form; use Filament\Support\Facades\FilamentIcon; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\BelongsToMany; @@ -130,12 +130,12 @@ protected function setUp(): void } }); - $this->createOptionUsing(static function (SelectTree $component, array $data, Form $form) { + $this->createOptionUsing(static function (SelectTree $component, array $data, Schema $schema) { $record = $component->getRelationship()->getRelated(); $record->fill($data); $record->save(); - $form->model($record)->saveRelationships(); + $schema->model($record)->saveRelationships(); return $component->getCustomKey($record); }); @@ -310,7 +310,7 @@ public function prepend(Closure|array|null $prepend = null): static if (is_array($this->prepend) && isset($this->prepend['name'], $this->prepend['value'])) { $this->prepend['value'] = (string) $this->prepend['value']; } else { - throw new \InvalidArgumentException('The provided prepend value must be an array with "name" and "value" keys.'); + throw new InvalidArgumentException('The provided prepend value must be an array with "name" and "value" keys.'); } return $this; @@ -510,9 +510,9 @@ public function getHiddenOptions(): array return $this->evaluate($this->hiddenOptions); } - public function getCreateOptionActionForm(Form $form): array|Form|null + public function getCreateOptionActionForm(Schema $schema): array|Schema|null { - return $this->evaluate($this->createOptionActionForm, ['form' => $form]); + return $this->evaluate($this->createOptionActionForm, ['form' => $schema]); } public function hasCreateOptionActionFormSchema(): bool @@ -560,19 +560,19 @@ public function getCreateOptionAction(): ?Action } $action = Action::make($this->getCreateOptionActionName()) - ->form(function (SelectTree $component, Form $form): array|Form|null { - return $component->getCreateOptionActionForm($form->model( + ->schema(function (SelectTree $component, Schema $schema): array|Schema|null { + return $component->getCreateOptionActionForm($schema->model( $component->getRelationship() ? $component->getRelationship()->getModel()::class : null, )); }) - ->action(static function (Action $action, array $arguments, SelectTree $component, array $data, ComponentContainer $form) { + ->action(static function (Action $action, array $arguments, SelectTree $component, array $data, Schema $schema) { if (! $component->getCreateOptionUsing()) { throw new Exception("Select field [{$component->getStatePath()}] must have a [createOptionUsing()] closure set."); } $createdOptionKey = $component->evaluate($component->getCreateOptionUsing(), [ 'data' => $data, - 'form' => $form, + 'form' => $schema, ]); $state = $component->getMultiple() @@ -591,7 +591,7 @@ public function getCreateOptionAction(): ?Action $action->callAfter(); - $form->fill(); + $schema->fill(); $action->halt(); })