label(__('filament.actions.models.wiki.attach_image.name')); $this->icon(__('filament-icons.actions.models.wiki.attach_image')); $this->visible(function ($livewire) { if (Auth::user()->cannot('create', Image::class)) { return false; } return $livewire instanceof BaseRelationManager && $livewire->getOwnerRecord() instanceof HasImages; }); } /** * Perform the action on the table. * * @param array $fields * @return void */ public function handle(array $fields): void { $action = new AttachImageActionAction(); /** @var BaseRelationManager $livewire */ $livewire = $this->getLivewire(); /** @var BaseModel&HasImages $model */ $model = $livewire->getOwnerRecord(); $action->handle($model, $fields, $this->facets); } /** * Get the fields available on the action. * * @param Form $form * @return Form */ public function getForm(Form $form): Form { $fields = []; foreach ($this->facets as $facet) { $fields[] = FileUpload::make($facet->name) ->label($facet->localize()) ->helperText(__('filament.actions.models.wiki.attach_image.help')) ->imageCropAspectRatio('2:3') ->image() ->imageEditor() ->imageEditorAspectRatios([null, '2:3']) ->storeFiles(false); } return $form ->schema($fields); } /** * Get the facets available for the action. * * @param ImageFacet[] $facets * @return static */ public function facets(array $facets): static { $this->facets = $facets; return $this; } }