Skip to content

Commit

Permalink
Base input to create collection based on attribute type (#1723)
Browse files Browse the repository at this point in the history
Currently when creating a new root collection we are assuming the
`TranslatedText` form component should be used. This will error if the
name attribute for a collection isn't translatable.

This PR finds the attribute and determines what type of input should be
used for the form.
  • Loading branch information
alecritson committed May 16, 2024
1 parent ff2e165 commit 37b2e15
Showing 1 changed file with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Lunar\Admin\Support\Actions\Collections;

use Filament\Actions\CreateAction;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Form;
use Lunar\Admin\Support\Forms\Components\TranslatedText;
use Lunar\Facades\DB;
Expand Down Expand Up @@ -55,8 +56,17 @@ public function setUp(): void
$this->success();
});

$attribute = Attribute::where('attribute_type', '=', Collection::class)
->where('handle', '=', 'name')->first();

$formInput = TextInput::class;

if ($attribute?->type == \Lunar\FieldTypes\TranslatedText::class) {
$formInput = TranslatedText::class;
}

$this->form([
TranslatedText::make('name')->required(),
$formInput::make('name')->required(),
]);

$this->label(
Expand Down

0 comments on commit 37b2e15

Please sign in to comment.