Skip to content

Commit

Permalink
Add attribute check on name attribute on base resource (#1795)
Browse files Browse the repository at this point in the history
  • Loading branch information
alecritson authored Aug 22, 2024
1 parent 63313d2 commit b68c030
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions packages/admin/src/Filament/Resources/ProductResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,15 @@
use Lunar\Admin\Filament\Widgets\Products\VariantSwitcherTable;
use Lunar\Admin\Support\Forms\Components\Attributes;
use Lunar\Admin\Support\Forms\Components\Tags as TagsComponent;
use Lunar\Admin\Support\Forms\Components\TranslatedText;
use Lunar\Admin\Support\Forms\Components\TranslatedText as TranslatedTextInput;
use Lunar\Admin\Support\RelationManagers\ChannelRelationManager;
use Lunar\Admin\Support\RelationManagers\MediaRelationManager;
use Lunar\Admin\Support\RelationManagers\PriceRelationManager;
use Lunar\Admin\Support\Resources\BaseResource;
use Lunar\Admin\Support\Tables\Columns\TranslatedTextColumn;
use Lunar\FieldTypes\Text;
use Lunar\FieldTypes\TranslatedText;
use Lunar\Models\Attribute;
use Lunar\Models\Currency;
use Lunar\Models\Product;
use Lunar\Models\ProductVariant;
Expand Down Expand Up @@ -172,8 +175,17 @@ public static function getBasePriceFormComponent(): Component

public static function getBaseNameFormComponent(): Component
{
return TranslatedText::make('name')
->label(__('lunarpanel::product.form.name.label'))->required();
$nameType = Attribute::whereHandle('name')
->whereAttributeType(static::getModel())
->first()?->type ?: TranslatedText::class;

$component = TranslatedTextInput::make('name');

if ($nameType == Text::class) {
$component = Forms\Components\TextInput::make('name');
}

return $component->label(__('lunarpanel::product.form.name.label'))->required();
}

protected static function getBrandFormComponent(): Component
Expand Down

0 comments on commit b68c030

Please sign in to comment.