Skip to content

Initial filament v4 #164

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

Closed
wants to merge 1 commit into from
Closed
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
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -62,6 +62,6 @@
]
}
},
"minimum-stability": "dev",
"minimum-stability": "beta",
"prefer-stable": true
}
32 changes: 16 additions & 16 deletions src/SelectTree.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
});
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -591,7 +591,7 @@ public function getCreateOptionAction(): ?Action

$action->callAfter();

$form->fill();
$schema->fill();

$action->halt();
})
Expand Down