diff --git a/.phpunit.cache/test-results b/.phpunit.cache/test-results index 63ab310..eb8c07e 100644 --- a/.phpunit.cache/test-results +++ b/.phpunit.cache/test-results @@ -1 +1 @@ -{"version":"pest_2.35.0","defects":[],"times":{"P\\Tests\\ExampleTest::__pest_evaluable_it_can_test":0.005,"P\\Tests\\ArchTest::__pest_evaluable_it_will_not_use_debugging_functions":0.144}} \ No newline at end of file +{"version":"pest_2.35.0","defects":[],"times":{"P\\Tests\\ExampleTest::__pest_evaluable_it_can_test":0.001,"P\\Tests\\ArchTest::__pest_evaluable_it_will_not_use_debugging_functions":0.137}} \ No newline at end of file diff --git a/config/filament-form-maker.php b/config/filament-form-maker.php index 38caa32..15596c2 100644 --- a/config/filament-form-maker.php +++ b/config/filament-form-maker.php @@ -9,4 +9,10 @@ 'extra_fields' => [ // 'field_name' => Field::class ], + + 'navigation_icons' => [ + 'builder' => 'tabler-forms', + 'collections' => 'tabler-category', + 'form_data' => 'tabler-file-text', + ], ]; diff --git a/resources/lang/en/form-maker.php b/resources/lang/en/form-maker.php index 424c5b3..f9576fb 100644 --- a/resources/lang/en/form-maker.php +++ b/resources/lang/en/form-maker.php @@ -2,5 +2,20 @@ // translations for Afsakar/FormMaker return [ - // + 'navigation_group' => 'Form Management', + + 'resources' => [ + 'builder' => [ + 'model_label' => 'Form Builder', + 'plural_model_label' => 'Form Builders', + ], + 'collections' => [ + 'model_label' => 'Form Collection', + 'plural_model_label' => 'Form Collections', + ], + 'form_data' => [ + 'model_label' => 'Form Data', + 'plural_model_label' => 'Form Data', + ], + ], ]; diff --git a/resources/lang/tr/form-maker.php b/resources/lang/tr/form-maker.php index 424c5b3..9d2f343 100644 --- a/resources/lang/tr/form-maker.php +++ b/resources/lang/tr/form-maker.php @@ -2,5 +2,108 @@ // translations for Afsakar/FormMaker return [ - // + 'navigation_group' => 'Form Yönetimi', + + 'resources' => [ + 'builder' => [ + 'section_title' => 'Form Bilgileri', + 'model_label' => 'Form Oluşturucu', + 'plural_model_label' => 'Form Oluşturucular', + 'inputs' => [ + 'name' => 'Adı', + ], + 'options' => [ + 'title' => 'Form Ayarları', + 'description' => 'Daha Fazla Form Ayarları', + 'notification_name' => 'Bildirim Adı', + 'background_color' => 'Arka Plan Rengi', + 'mail_notifications' => 'Mail Bildirimleri', + 'user_emails' => 'Kullanıcı E-postaları', + 'user_emails_hint' => 'Forum\'un doldurulduktan sonra iletilmesini istediğiniz kullanıcıları seçiniz.', + 'static_fields' => [ + 'full_span' => 'Tam Genişlik', + 'placeholder' => 'Placeholder', + 'notification_name' => 'Bildirim Adı', + 'is_required' => 'Zorunlu Alan', + 'hidden_label' => 'Gizli Etiket', + 'field_id' => 'Alan ID', + 'html_id' => 'HTML ID', + 'column_span' => 'Sütun Genişliği', + 'helper_text' => 'Yardımcı Metin', + ], + 'select_field' => [ + 'title' => 'Seçim Kutusu Ayarları', + 'is_multiple' => 'Çoklu Seçim', + 'is_searchable' => 'Arama Yapılabilir', + 'data_source' => 'Veri Kaynağı', + ], + 'checkbox_radio_field' => [ + 'title' => 'Onay Kutusu / Seçim Düğmesi Ayarları', + 'data_source' => 'Veri Kaynağı', + 'one_column' => 'Tek Sütun', + 'two_columns' => 'İki Sütun', + 'three_columns' => 'Üç Sütun', + 'four_columns' => 'Dört Sütun', + ], + 'text_field' => [ + 'title' => 'Metin Alanı Ayarları', + 'field_type' => 'Alan Tipi', + 'types' => [ + 'text' => 'Metin', + 'email' => 'E-posta', + 'url' => 'URL', + 'number' => 'Sayı', + ], + 'max_value' => 'Maksimum Değer', + 'min_value' => 'Minimum Değer', + ], + 'file_field' => [ + 'title' => 'Dosya Alanı Ayarları', + 'max_size' => 'Maksimum Dosya Sayısı', + 'hint' => 'KB cinsinden', + 'accepted_file_types' => 'İzin Verilen Uzantılar', + 'image' => 'Resim', + ], + 'visibility' => [ + 'title' => 'Koşullu Görünürlük', + 'active' => 'Koşullu Görünürlük Aktif', + 'fieldId' => 'Koşul Bağlanacak Alan', + 'values' => 'Görünürlük Değeri', + 'values_helper_text' => 'Eğer herhangi bir değer seçildiği takdirde görünür olmasını istiyorsanız bu alanı boş bırakın.', + ], + ], + 'sections' => [ + 'title' => 'Bölümler', + 'count' => 'Bölüm Sayısı', + 'add_action_label' => 'Bölüm Ekle', + 'new_section_label' => 'Yeni Bölüm', + 'inputs' => [ + 'title' => 'Başlık', + 'columns' => 'Sütun Sayısı', + 'columns_hint' => 'Bölümdeki sütun sayısı', + ], + ], + 'fields' => [ + 'title' => 'Alanlar', + 'add_action_label' => 'Alan Ekle', + 'new_field_label' => 'Yeni Alan', + 'options' => [ + 'title' => 'Alan Ayarları', + 'description' => 'Daha Fazla Alan Ayarları', + ], + 'inputs' => [ + 'name' => 'Alan Adı', + 'type' => 'Alan Tipi', + ], + ], + ], + 'collections' => [ + 'model_label' => 'Form Koleksiyonu', + 'plural_model_label' => 'Form Koleksiyonları', + ], + 'form_data' => [ + 'model_label' => 'Form Verileri', + 'plural_model_label' => 'Form Verileri', + ], + ], ]; diff --git a/src/Fields/Classes/Checkbox.php b/src/Fields/Classes/Checkbox.php index c091691..355ee90 100644 --- a/src/Fields/Classes/Checkbox.php +++ b/src/Fields/Classes/Checkbox.php @@ -13,6 +13,7 @@ public static function make(FormBuilderField $field): Forms\Components\Field { return Forms\Components\CheckboxList::make(data_get($field, 'options.fieldId')) ->label(data_get($field, 'name')) + ->hiddenLabel(data_get($field, 'options.hidden_label', false)) ->columnSpan([ 'xs' => 1, 'sm' => 1, @@ -29,6 +30,7 @@ public static function make(FormBuilderField $field): Forms\Components\Field 'xl' => data_get($field, 'options.columns', 2), 'default' => data_get($field, 'options.columns', 2), ]) + ->reactive() ->gridDirection('row') ->id(data_get($field, 'options.htmlId')) ->options(self::getOptions($field)) @@ -47,8 +49,9 @@ public static function make(FormBuilderField $field): Forms\Components\Field return $get($fieldId); } - return $value === $get($fieldId); + return in_array($get($fieldId), $value); }) + ->helperText(data_get($field, 'options.helper_text', null)) ->required(data_get($field, 'options.is_required', false)); } diff --git a/src/Fields/Classes/DatePicker.php b/src/Fields/Classes/DatePicker.php index f3f238e..74011cd 100644 --- a/src/Fields/Classes/DatePicker.php +++ b/src/Fields/Classes/DatePicker.php @@ -11,8 +11,9 @@ class DatePicker extends Field public static function make(FormBuilderField $field): Forms\Components\Field { return Forms\Components\DatePicker::make(data_get($field, 'options.fieldId')) - ->hiddenLabel() - ->placeholder(data_get($field, 'options.is_required', false) ? data_get($field, 'name') . ' *' : data_get($field, 'name')) + ->label(data_get($field, 'name')) + ->hiddenLabel(data_get($field, 'options.hidden_label', false)) + ->placeholder(data_get($field, 'options.hidden_label', false) ? (data_get($field, 'options.placeholder') !== null ? data_get($field, 'options.placeholder') : data_get($field, 'name')) : null) ->columnSpan([ 'xs' => 1, 'sm' => 1, @@ -21,6 +22,7 @@ public static function make(FormBuilderField $field): Forms\Components\Field 'xl' => data_get($field, 'options.column_span', 1), 'default' => data_get($field, 'options.column_span', 1), ]) + ->reactive() ->id(data_get($field, 'options.htmlId')) ->closeOnDateSelection() ->format('d F Y') @@ -41,8 +43,9 @@ public static function make(FormBuilderField $field): Forms\Components\Field return $get($fieldId); } - return $value === $get($fieldId); + return in_array($get($fieldId), $value); }) + ->helperText(data_get($field, 'options.helper_text', null)) ->required(data_get($field, 'options.is_required', false)); } } diff --git a/src/Fields/Classes/FileInput.php b/src/Fields/Classes/FileInput.php index 34e188b..adb72d3 100644 --- a/src/Fields/Classes/FileInput.php +++ b/src/Fields/Classes/FileInput.php @@ -14,6 +14,8 @@ public static function make(FormBuilderField $field): Forms\Components\Field { return Forms\Components\FileUpload::make(data_get($field, 'options.fieldId')) ->label(data_get($field, 'name')) + ->hiddenLabel(data_get($field, 'options.hidden_label', false)) + ->placeholder(data_get($field, 'options.hidden_label', false) ? (data_get($field, 'options.placeholder') !== null ? data_get($field, 'options.placeholder') : data_get($field, 'name')) : null) ->columnSpan([ 'xs' => 1, 'sm' => 1, @@ -22,6 +24,7 @@ public static function make(FormBuilderField $field): Forms\Components\Field 'xl' => data_get($field, 'options.column_span', 1), 'default' => data_get($field, 'options.column_span', 1), ]) + ->reactive() ->id(data_get($field, 'options.htmlId')) ->acceptedFileTypes(data_get($field, 'options.accepted_file_types') ?? ['application/pdf']) ->maxSize(data_get($field, 'options.max_size', 5120)) @@ -42,8 +45,9 @@ public static function make(FormBuilderField $field): Forms\Components\Field return $get($fieldId); } - return $value === $get($fieldId); + return in_array($get($fieldId), $value); }) + ->helperText(data_get($field, 'options.helper_text', null)) ->required(data_get($field, 'options.is_required', false)); } } diff --git a/src/Fields/Classes/PhoneInput.php b/src/Fields/Classes/PhoneInput.php index fe6e9e6..cf627af 100644 --- a/src/Fields/Classes/PhoneInput.php +++ b/src/Fields/Classes/PhoneInput.php @@ -14,8 +14,9 @@ class PhoneInput extends Field public static function make(FormBuilderField $field): Forms\Components\Field { return BasePhoneInput::make(data_get($field, 'options.fieldId')) - ->hiddenLabel() - ->placeholder(data_get($field, 'options.is_required', false) ? data_get($field, 'name') . ' *' : data_get($field, 'name')) + ->label(data_get($field, 'name')) + ->hiddenLabel(data_get($field, 'options.hidden_label', false)) + ->placeholder(data_get($field, 'options.hidden_label', false) ? (data_get($field, 'options.placeholder') !== null ? data_get($field, 'options.placeholder') : data_get($field, 'name')) : null) ->columnSpan([ 'xs' => 1, 'sm' => 1, @@ -24,6 +25,7 @@ public static function make(FormBuilderField $field): Forms\Components\Field 'xl' => data_get($field, 'options.column_span', 1), 'default' => data_get($field, 'options.column_span', 1), ]) + ->reactive() ->id(data_get($field, 'options.htmlId')) ->visible(function ($get) use ($field) { $visibilty = data_get($field, 'options.visibility'); @@ -40,8 +42,9 @@ public static function make(FormBuilderField $field): Forms\Components\Field return $get($fieldId); } - return $value === $get($fieldId); + return in_array($get($fieldId), $value); }) + ->helperText(data_get($field, 'options.helper_text', null)) ->required(data_get($field, 'options.is_required', false)); } } diff --git a/src/Fields/Classes/Radio.php b/src/Fields/Classes/Radio.php index f4b66c7..2b6bb76 100644 --- a/src/Fields/Classes/Radio.php +++ b/src/Fields/Classes/Radio.php @@ -29,6 +29,7 @@ public static function make(FormBuilderField $field): Forms\Components\Field 'xl' => data_get($field, 'options.columns', 2), 'default' => data_get($field, 'options.columns', 2), ]) + ->reactive() ->gridDirection('row') ->id(data_get($field, 'options.htmlId')) ->options(self::getOptions($field)) @@ -47,8 +48,9 @@ public static function make(FormBuilderField $field): Forms\Components\Field return $get($fieldId); } - return $value === $get($fieldId); + return in_array($get($fieldId), $value); }) + ->helperText(data_get($field, 'options.helper_text', null)) ->required(data_get($field, 'options.is_required', false)); } diff --git a/src/Fields/Classes/Select.php b/src/Fields/Classes/Select.php index 9622001..7d6e7a8 100644 --- a/src/Fields/Classes/Select.php +++ b/src/Fields/Classes/Select.php @@ -12,8 +12,9 @@ class Select extends Field public static function make(FormBuilderField $field): Forms\Components\Field { return Forms\Components\Select::make(data_get($field, 'options.fieldId')) - ->hiddenLabel() - ->placeholder(data_get($field, 'options.is_required', false) ? data_get($field, 'name') . ' *' : data_get($field, 'name')) + ->label(data_get($field, 'name')) + ->hiddenLabel(data_get($field, 'options.hidden_label', false)) + ->placeholder(data_get($field, 'options.hidden_label', false) ? (data_get($field, 'options.placeholder') !== null ? data_get($field, 'options.placeholder') : data_get($field, 'name')) : null) ->columnSpan([ 'xs' => 1, 'sm' => 1, @@ -43,8 +44,9 @@ public static function make(FormBuilderField $field): Forms\Components\Field return $get($fieldId); } - return $value === $get($fieldId); + return in_array($get($fieldId), $value); }) + ->helperText(data_get($field, 'options.helper_text', null)) ->required(data_get($field, 'options.is_required', false)); } diff --git a/src/Fields/Classes/TextInput.php b/src/Fields/Classes/TextInput.php index da6b689..40fa30c 100644 --- a/src/Fields/Classes/TextInput.php +++ b/src/Fields/Classes/TextInput.php @@ -11,9 +11,10 @@ class TextInput extends Field public static function make(FormBuilderField $field): Forms\Components\Field { return Forms\Components\TextInput::make(data_get($field, 'options.fieldId')) - ->hiddenLabel() + ->label(data_get($field, 'name')) + ->hiddenLabel(data_get($field, 'options.hidden_label', false)) + ->placeholder(data_get($field, 'options.hidden_label', false) ? (data_get($field, 'options.placeholder') !== null ? data_get($field, 'options.placeholder') : data_get($field, 'name')) : null) ->type(data_get($field, 'options.field_type', 'text')) - ->placeholder(data_get($field, 'options.is_required', false) ? data_get($field, 'name') . ' *' : data_get($field, 'name')) ->columnSpan([ 'xs' => 1, 'sm' => 1, @@ -22,6 +23,7 @@ public static function make(FormBuilderField $field): Forms\Components\Field 'xl' => data_get($field, 'options.column_span', 1), 'default' => data_get($field, 'options.column_span', 1), ]) + ->reactive() ->id(data_get($field, 'options.htmlId')) ->maxValue(data_get($field, 'options.max_value', null)) ->minValue(data_get($field, 'options.min_value', null)) @@ -40,8 +42,9 @@ public static function make(FormBuilderField $field): Forms\Components\Field return $get($fieldId); } - return $value === $get($fieldId); + return in_array($get($fieldId), $value); }) + ->helperText(data_get($field, 'options.helper_text', null)) ->required(data_get($field, 'options.is_required', false)); } } diff --git a/src/Fields/Classes/Textarea.php b/src/Fields/Classes/Textarea.php index cdd6782..4be3f14 100644 --- a/src/Fields/Classes/Textarea.php +++ b/src/Fields/Classes/Textarea.php @@ -11,8 +11,9 @@ class Textarea extends Field public static function make(FormBuilderField $field): \Filament\Forms\Components\Field { return Forms\Components\Textarea::make(data_get($field, 'options.fieldId')) - ->hiddenLabel() - ->placeholder(data_get($field, 'options.is_required', false) ? data_get($field, 'name') . ' *' : data_get($field, 'name')) + ->label(data_get($field, 'name')) + ->hiddenLabel(data_get($field, 'options.hidden_label', false)) + ->placeholder(data_get($field, 'options.hidden_label', false) ? (data_get($field, 'options.placeholder') !== null ? data_get($field, 'options.placeholder') : data_get($field, 'name')) : null) ->columnSpan([ 'xs' => 1, 'sm' => 1, @@ -21,6 +22,7 @@ public static function make(FormBuilderField $field): \Filament\Forms\Components 'xl' => data_get($field, 'options.column_span', 1), 'default' => data_get($field, 'options.column_span', 1), ]) + ->reactive() ->autosize() ->id(data_get($field, 'options.htmlId')) ->visible(function ($get) use ($field) { @@ -38,8 +40,9 @@ public static function make(FormBuilderField $field): \Filament\Forms\Components return $get($fieldId); } - return $value === $get($fieldId); + return in_array($get($fieldId), $value); }) + ->helperText(data_get($field, 'options.helper_text', null)) ->required(data_get($field, 'options.is_required', false)); } } diff --git a/src/Filament/Resources/FormBuilderCollectionResource.php b/src/Filament/Resources/FormBuilderCollectionResource.php index 05f8673..da44c76 100644 --- a/src/Filament/Resources/FormBuilderCollectionResource.php +++ b/src/Filament/Resources/FormBuilderCollectionResource.php @@ -10,22 +10,37 @@ use Filament\Resources\Resource; use Filament\Tables; use Filament\Tables\Table; +use Illuminate\Contracts\Support\Htmlable; class FormBuilderCollectionResource extends Resource { protected static ?string $model = FormBuilderCollection::class; - protected static ?string $navigationIcon = 'tabler-category'; + protected static ?string $slug = 'form-management/collections'; - protected static ?string $slug = 'form-builder-collections'; + protected static ?int $navigationSort = 2; - protected static ?string $navigationGroup = 'Form Yönetimi'; + protected static ?string $recordTitleAttribute = 'name'; - protected static ?int $navigationSort = 2; + public static function getNavigationGroup(): string + { + return trans('filament-form-maker::form-maker.navigation_group'); + } - protected static ?string $modelLabel = 'Form Koleksiyonu'; + public static function getModelLabel(): string + { + return trans('filament-form-maker::form-maker.resources.collections.model_label'); + } + + public static function getPluralModelLabel(): string + { + return trans('filament-form-maker::form-maker.resources.collections.plural_model_label'); + } - protected static ?string $pluralModelLabel = 'Form Koleksiyonları'; + public static function getNavigationIcon(): string | Htmlable | null + { + return config('filament-form-maker.navigation_icons.collections', 'tabler-forms'); + } public static function form(Form $form): Form { @@ -49,7 +64,6 @@ public static function form(Form $form): Form Forms\Components\Select::make('model') ->label('Model') ->visible(fn ($get) => $get('type') === 'model') - ->live() ->native(false) ->preload() ->options(function () { @@ -67,12 +81,12 @@ public static function form(Form $form): Form ->addActionLabel('Değer Ekle') ->grid(3) ->schema([ - Forms\Components\TextInput::make('value') - ->label('Değer') - ->required(), Forms\Components\TextInput::make('label') ->label('Etiket') ->required(), + Forms\Components\TextInput::make('value') + ->label('Değer') + ->required(), ]), ]), ]); diff --git a/src/Filament/Resources/FormBuilderDataResource.php b/src/Filament/Resources/FormBuilderDataResource.php index 90489a7..9884405 100644 --- a/src/Filament/Resources/FormBuilderDataResource.php +++ b/src/Filament/Resources/FormBuilderDataResource.php @@ -13,6 +13,7 @@ use Filament\Resources\Resource; use Filament\Tables; use Filament\Tables\Table; +use Illuminate\Contracts\Support\Htmlable; use Illuminate\Database\Eloquent\Model; use Illuminate\Support\HtmlString; @@ -20,21 +21,30 @@ class FormBuilderDataResource extends Resource { protected static ?string $model = FormBuilderData::class; - protected static ?string $navigationIcon = 'tabler-report'; + protected static ?string $slug = 'form-management/data'; - protected static ?string $slug = 'form-data'; + protected static ?int $navigationSort = 3; - protected static ?string $navigationGroup = 'Form Yönetimi'; + protected static ?string $recordTitleAttribute = 'name'; - protected static ?int $navigationSort = 3; + public static function getNavigationGroup(): string + { + return trans('filament-form-maker::form-maker.navigation_group'); + } - protected static ?string $modelLabel = 'Formlar'; + public static function getModelLabel(): string + { + return trans('filament-form-maker::form-maker.resources.form_data.model_label'); + } - protected static ?string $pluralModelLabel = 'Formlar'; + public static function getPluralModelLabel(): string + { + return trans('filament-form-maker::form-maker.resources.form_data.plural_model_label'); + } - public static function getRecordTitle(?Model $record): ?string + public static function getNavigationIcon(): string | Htmlable | null { - return 'name'; + return config('filament-form-maker.navigation_icons.form_data', 'tabler-forms'); } public static function getNavigationBadge(): ?string diff --git a/src/Filament/Resources/FormBuilderResource.php b/src/Filament/Resources/FormBuilderResource.php index d109e0f..74e84a0 100644 --- a/src/Filament/Resources/FormBuilderResource.php +++ b/src/Filament/Resources/FormBuilderResource.php @@ -11,6 +11,7 @@ use Filament\Resources\Resource; use Filament\Tables; use Filament\Tables\Table; +use Illuminate\Contracts\Support\Htmlable; use Illuminate\Support\Str; class FormBuilderResource extends Resource @@ -19,48 +20,52 @@ class FormBuilderResource extends Resource protected static ?string $model = FormBuilder::class; - protected static ?string $navigationIcon = 'tabler-forms'; + protected static ?string $slug = 'form-management/forms'; - protected static ?string $slug = 'form-builder'; + protected static ?int $navigationSort = 1; - protected static ?string $navigationGroup = 'Form Yönetimi'; + protected static ?string $recordTitleAttribute = 'name'; - protected static ?int $navigationSort = 1; + public static function getNavigationGroup(): string + { + return trans('filament-form-maker::form-maker.navigation_group'); + } - protected static ?string $modelLabel = 'Form Oluşturucu'; + public static function getModelLabel(): string + { + return trans('filament-form-maker::form-maker.resources.builder.model_label'); + } - protected static ?string $pluralModelLabel = 'Form Oluşturucular'; + public static function getPluralModelLabel(): string + { + return trans('filament-form-maker::form-maker.resources.builder.plural_model_label'); + } - protected static ?string $recordTitleAttribute = 'name'; + public static function getNavigationIcon(): string | Htmlable | null + { + return config('filament-form-maker.navigation_icons.builder', 'tabler-forms'); + } public static function form(Form $form): Form { return $form ->columns(1) ->schema([ - Forms\Components\Section::make('Form Bilgileri') + Forms\Components\Section::make(trans('filament-form-maker::form-maker.resources.builder.section_title')) ->headerActions([ Forms\Components\Actions\Action::make('form_settings') ->hiddenLabel() ->slideOver() - ->tooltip('Form Ayarları') + ->tooltip(trans('filament-form-maker::form-maker.resources.builder.options.title')) ->icon('heroicon-m-cog') ->modalIcon('heroicon-m-cog') - ->modalHeading('Form Ayarları') - ->modalDescription('Daha Fazla Form Ayarları') - ->fillForm(fn ( - $state, - array $arguments, - $component - ) => $component->getState()) - ->form(function ($get, array $arguments, $component, $state) { - $arguments = $component->getState(); - - return [ - static::staticFormBuilderOptions(), - ]; - }) - ->action(function (array $data, array $arguments, $component): void { + ->modalHeading(trans('filament-form-maker::form-maker.resources.builder.options.title')) + ->modalDescription(trans('filament-form-maker::form-maker.resources.builder.options.description')) + ->fillForm(fn ($component) => $component->getState()) + ->form([ + static::staticFormBuilderOptions(), + ]) + ->action(function (array $data, $component): void { $state = $component->getState(); $state = array_merge($state, $data); $component->state($state); @@ -70,15 +75,15 @@ public static function form(Form $form): Form Forms\Components\Grid::make() ->schema([ Forms\Components\TextInput::make('name') - ->label('Adı') + ->label(trans('filament-form-maker::form-maker.resources.builder.inputs.name')) ->required() + ->columnSpanFull() ->live(true) ->unique('form_builders', 'name', ignoreRecord: true) ->afterStateUpdated(function ($state, $set) { $set('slug', str($state)->slug()); }), - Forms\Components\TextInput::make('slug') - ->label('Kısa Adı') + Forms\Components\Hidden::make('slug') ->hintIcon('heroicon-s-information-circle', 'Kısa Ad sadece alan oluşturulduğunda otomatik olarak oluşturulur. Kullanıcı için herhangi bir etkisi yoktur.') ->unique('form_builders', 'slug', ignoreRecord: true) ->dehydrateStateUsing(function ($state) { @@ -89,9 +94,9 @@ public static function form(Form $form): Form ]), ]), Forms\Components\Repeater::make('sections') - ->label('Bölümler') - ->addActionLabel('Bölüm Ekle') - ->itemLabel(fn ($state) => $state['title'] ?? 'Yeni Bölüm') + ->label(trans('filament-form-maker::form-maker.resources.builder.sections.title')) + ->addActionLabel(trans('filament-form-maker::form-maker.resources.builder.sections.add_action_label')) + ->itemLabel(fn ($state) => $state['title'] ?? trans('filament-form-maker::form-maker.resources.builder.sections.new_section_label')) ->collapsed(fn (string $operation) => $operation === 'edit') ->cloneable() ->relationship('sections') @@ -104,49 +109,46 @@ public static function form(Form $form): Form Forms\Components\Grid::make() ->schema([ Forms\Components\TextInput::make('title') - ->label('Başlık') + ->label(trans('filament-form-maker::form-maker.resources.builder.sections.inputs.title')) ->lazy() ->nullable(), Forms\Components\Select::make('columns') ->options(fn (): array => array_combine(range(1, 12), range(1, 12))) - ->label('Sütun Sayısı') + ->label(trans('filament-form-maker::form-maker.resources.builder.sections.inputs.columns')) ->required() ->searchable() ->live(onBlur: true) ->default(1) - ->hint('Bölümün sütun sayısını belirler.'), + ->hint(trans('filament-form-maker::form-maker.resources.builder.sections.inputs.columns_hint')), ]), Forms\Components\Repeater::make('fields') - ->label('Alanlar') - ->addActionLabel('Alan Ekle') + ->label(trans('filament-form-maker::form-maker.resources.builder.fields.title')) + ->addActionLabel(trans('filament-form-maker::form-maker.resources.builder.fields.add_action_label')) ->minItems(1) ->grid(3) ->visible(fn ($get) => $get('columns')) - ->itemLabel(fn ($state) => $state['name'] ?? 'Yeni Alan') + ->itemLabel(fn ($state) => $state['name'] ?? trans('filament-form-maker::form-maker.resources.builder.fields.new_field_label')) ->collapsed(fn (string $operation) => $operation === 'edit') ->cloneable() ->deleteAction( fn ($action) => $action->requiresConfirmation(), ) ->extraItemActions([ - Forms\Components\Actions\Action::make('Alan Ayarları') + Forms\Components\Actions\Action::make(trans('filament-form-maker::form-maker.resources.builder.fields.options.title')) ->slideOver() - ->tooltip('Alan Ayarları') + ->tooltip(trans('filament-form-maker::form-maker.resources.builder.fields.options.title')) ->icon('heroicon-m-cog') ->modalIcon('heroicon-m-cog') - ->modalDescription('Daha Fazla Alan Ayarları') - ->fillForm(fn ( - $state, - $get, - array $arguments, - Forms\Components\Repeater $component - ) => $component->getItemState($arguments['item'])) - ->form(function ($get, array $arguments, Forms\Components\Repeater $component, $state) { + ->modalDescription(trans('filament-form-maker::form-maker.resources.builder.fields.options.description')) + ->fillForm(fn (array $arguments, Forms\Components\Repeater $component) => $component->getItemState($arguments['item'])) + ->form(function ($get, array $arguments, Forms\Components\Repeater $component) { $arguments = $component->getState()[$arguments['item']]; $type = $arguments['type'] ?? null; + $columns = $get('columns'); + $dynamicOptions = match ($type) { 'select' => static::selectFieldOptions(), 'checkbox', 'radio' => static::checkboxRadioFieldOptions(), @@ -159,8 +161,6 @@ public static function form(Form $form): Form $fields = $parentComponent?->getState(); - $columns = $get('columns'); - return [ static::staticFieldOptions($columns), static::getConditionalFieldOptions($fields), @@ -198,7 +198,7 @@ public static function form(Form $form): Form ->orderColumn('order_column') ->schema([ Forms\Components\TextInput::make('name') - ->label('Alan Adı') + ->label(trans('filament-form-maker::form-maker.resources.builder.fields.inputs.name')) ->lazy() ->afterStateUpdated(function ($state, $set, $context) { if ($context === 'edit') { @@ -208,7 +208,7 @@ public static function form(Form $form): Form }) ->required(), Forms\Components\Select::make('type') - ->label('Alan Tipi') + ->label(trans('filament-form-maker::form-maker.resources.builder.fields.inputs.type')) ->options(FieldTypes::options()) ->native(false) ->searchable() @@ -226,9 +226,10 @@ public static function table(Table $table): Table ->columns([ Tables\Columns\TextColumn::make('name') ->searchable() - ->label('Adı'), - Tables\Columns\TextColumn::make('slug') - ->label('Kısa Adı'), + ->label(trans('filament-form-maker::form-maker.resources.builder.inputs.name')), + Tables\Columns\TextColumn::make('sections_count') + ->label(trans('filament-form-maker::form-maker.resources.builder.sections.count')) + ->counts('sections'), ]) ->filters([ // @@ -244,16 +245,14 @@ public static function table(Table $table): Table }) ->form([ Forms\Components\TextInput::make('name') - ->label('Adı') + ->label(trans('filament-form-maker::form-maker.resources.builder.inputs.name')) ->required() - ->live(true) + ->live() ->unique('form_builders', 'name', ignoreRecord: true) ->afterStateUpdated(function ($state, $set) { $set('slug', str($state)->slug()); }), - Forms\Components\TextInput::make('slug') - ->label('Kısa Adı') - ->readOnly() + Forms\Components\Hidden::make('slug') ->hintIcon('heroicon-s-information-circle', 'Kısa Ad sadece alan oluşturulduğunda otomatik olarak oluşturulur. Kullanıcı için herhangi bir etkisi yoktur.') ->unique('form_builders', 'slug', ignoreRecord: true) ->required(), @@ -266,7 +265,6 @@ public static function table(Table $table): Table $newSection->form_builder_id = $replica->id; $newSection->save(); - // Her section'ın fields ilişkisini de kopyala foreach ($section->fields as $field) { $newField = $field->replicate(); $newField->form_builder_section_id = $newSection->id; diff --git a/src/Models/Traits/HasHiddenOptions.php b/src/Models/Traits/HasHiddenOptions.php index 991e4b9..c2d578d 100644 --- a/src/Models/Traits/HasHiddenOptions.php +++ b/src/Models/Traits/HasHiddenOptions.php @@ -23,6 +23,8 @@ protected static function hiddenFieldLabels(): Forms\Components\Group return Forms\Components\Group::make() ->statePath('options') ->schema([ + Forms\Components\Hidden::make('placeholder')->default(null), + Forms\Components\Hidden::make('hidden_label')->default(false), Forms\Components\Hidden::make('is_required')->default(true), Forms\Components\Hidden::make('is_multiple')->default(false), Forms\Components\Hidden::make('is_searchable')->default(false), @@ -31,6 +33,7 @@ protected static function hiddenFieldLabels(): Forms\Components\Group Forms\Components\Hidden::make('field_type')->default('text'), Forms\Components\Hidden::make('column_span')->default(1), Forms\Components\Hidden::make('data_source'), + Forms\Components\Hidden::make('helper_text')->default(null), ]) ->columns(1); } diff --git a/src/Models/Traits/HasOptions.php b/src/Models/Traits/HasOptions.php index cb24d16..9424727 100644 --- a/src/Models/Traits/HasOptions.php +++ b/src/Models/Traits/HasOptions.php @@ -22,30 +22,40 @@ protected static function staticFieldOptions(?int $columns): Forms\Components\Gr $colspanOptions[$column] = $column . '/' . $columns; } - $colspanOptions['full'] = 'Tam Genişlik'; + $colspanOptions['full'] = trans('filament-form-maker::form-maker.resources.builder.options.static_fields.full_span'); return [ - Forms\Components\TextInput::make('static_name') - ->label('Bildirim Adı') - ->nullable(), - Forms\Components\Toggle::make('is_required') - ->label('Zorunlu Alan') - ->default(true), - Forms\Components\TextInput::make('fieldId') - ->required() - ->default(str()->random(6)) - ->readOnly() - ->label(__('Alan ID')), - Forms\Components\TextInput::make('htmlId') - ->required() - ->default(str()->random(6)) - ->readOnly() - ->label(__('HTML ID')), + Forms\Components\Grid::make() + ->schema([ + Forms\Components\TextInput::make('static_name') + ->label(trans('filament-form-maker::form-maker.resources.builder.options.static_fields.notification_name')) + ->nullable(), + Forms\Components\TextInput::make('placeholder') + ->label(trans('filament-form-maker::form-maker.resources.builder.options.static_fields.placeholder')) + ->nullable(), + Forms\Components\Toggle::make('is_required') + ->label(trans('filament-form-maker::form-maker.resources.builder.options.static_fields.is_required')) + ->default(true), + Forms\Components\Toggle::make('hidden_label') + ->label(trans('filament-form-maker::form-maker.resources.builder.options.static_fields.hidden_label')) + ->default(false), + Forms\Components\Hidden::make('fieldId') + ->required() + ->default(str()->random(6)) + ->label(trans('filament-form-maker::form-maker.resources.builder.options.static_fields.field_id')), + Forms\Components\Hidden::make('htmlId') + ->required() + ->default(str()->random(6)) + ->label(trans('filament-form-maker::form-maker.resources.builder.options.static_fields.html_id')), + ]), Forms\Components\Select::make('column_span') - ->label('Sütun Genişliği') + ->label(trans('filament-form-maker::form-maker.resources.builder.options.static_fields.column_span')) ->options($colspanOptions) ->searchable() ->default('1'), + Forms\Components\TextInput::make('helper_text') + ->label(trans('filament-form-maker::form-maker.resources.builder.options.static_fields.helper_text')) + ->nullable(), ]; }) ->columns(1); @@ -57,16 +67,16 @@ protected static function staticFormBuilderOptions(): Forms\Components\Group ->statePath('options') ->schema([ Forms\Components\TextInput::make('static_name') - ->label('Bildirim Adı') + ->label(trans('filament-form-maker::form-maker.resources.builder.options.notification_name')) ->nullable(), Forms\Components\ColorPicker::make('background_color') - ->label('Arka Plan Rengi') + ->label(trans('filament-form-maker::form-maker.resources.builder.options.background_color')) ->default('transparent'), - Forms\Components\Section::make('Mail Bildirimleri') + Forms\Components\Section::make(trans('filament-form-maker::form-maker.resources.builder.options.mail_notifications')) ->schema([ Forms\Components\Select::make('admin_ids') - ->label('Kullanıcı E-postaları') - ->hintIcon('tabler-info-circle', 'Forum\'un doldurulduktan sonra iletilmesini istediğiniz kullanıcıları seçiniz.') + ->label(trans('filament-form-maker::form-maker.resources.builder.options.user_emails')) + ->hintIcon('tabler-info-circle', trans('filament-form-maker::form-maker.resources.builder.options.user_emails_hint')) ->native(false) ->searchable() ->options(function () { @@ -83,18 +93,18 @@ protected static function staticFormBuilderOptions(): Forms\Components\Group protected static function selectFieldOptions(): array { return [ - Forms\Components\Section::make('Seçim Kutusu Ayarları') + Forms\Components\Section::make(trans('filament-form-maker::form-maker.resources.builder.options.select_field.title')) ->collapsed() ->statePath('options') ->schema([ Forms\Components\Toggle::make('is_multiple') - ->label('Çoklu Seçim') + ->label(trans('filament-form-maker::form-maker.resources.builder.options.select_field.is_multiple')) ->default(false), Forms\Components\Toggle::make('is_searchable') - ->label('Arama Yapılabilir') + ->label(trans('filament-form-maker::form-maker.resources.builder.options.select_field.is_searchable')) ->default(false), Forms\Components\Select::make('data_source') - ->label('Veri Kaynağı') + ->label(trans('filament-form-maker::form-maker.resources.builder.options.select_field.data_source')) ->native(false) ->searchable() ->preload() @@ -107,13 +117,12 @@ protected static function selectFieldOptions(): array protected static function checkboxRadioFieldOptions(): array { return [ - Forms\Components\Section::make('Onay Kutusu / Seçim Düğmesi Ayarları') + Forms\Components\Section::make(trans('filament-form-maker::form-maker.resources.builder.options.checkbox_radio_field.title')) ->collapsed() ->statePath('options') ->schema([ Forms\Components\Select::make('data_source') - ->label('Veri Kaynağı') - ->native(false) + ->label(trans('filament-form-maker::form-maker.resources.builder.options.checkbox_radio_field.data_source')) ->searchable() ->preload() ->options(FormBuilderCollection::pluck('name', 'id')->toArray()) @@ -122,10 +131,10 @@ protected static function checkboxRadioFieldOptions(): array ->label('Sütun Sayısı') ->inline() ->options([ - 1 => 'Tek Sütun', - 2 => 'İki Sütun', - 3 => 'Üç Sütun', - 4 => 'Dört Sütun', + 1 => trans('filament-form-maker::form-maker.resources.builder.options.checkbox_radio_field.one_column'), + 2 => trans('filament-form-maker::form-maker.resources.builder.options.checkbox_radio_field.two_columns'), + 3 => trans('filament-form-maker::form-maker.resources.builder.options.checkbox_radio_field.three_columns'), + 4 => trans('filament-form-maker::form-maker.resources.builder.options.checkbox_radio_field.four_columns'), ]) ->default(2), ]), @@ -135,21 +144,21 @@ protected static function checkboxRadioFieldOptions(): array protected static function textFieldOptions(): array { return [ - Forms\Components\Section::make('Metin Alanı Ayarları') + Forms\Components\Section::make(trans('filament-form-maker::form-maker.resources.builder.options.text_field.title')) ->collapsed() ->statePath('options') ->schema([ Forms\Components\Select::make('field_type') - ->label('Metin Alanı Tipi') + ->label(trans('filament-form-maker::form-maker.resources.builder.options.text_field.field_type')) ->native(false) ->searchable() ->preload() ->live() ->options([ - 'text' => 'Metin', - 'email' => 'E-posta', - 'url' => 'URL', - 'number' => 'Sayı', + 'text' => trans('filament-form-maker::form-maker.resources.builder.options.text_field.types.text'), + 'email' => trans('filament-form-maker::form-maker.resources.builder.options.text_field.types.email'), + 'url' => trans('filament-form-maker::form-maker.resources.builder.options.text_field.types.url'), + 'number' => trans('filament-form-maker::form-maker.resources.builder.options.text_field.types.number'), ]) ->default('text') ->required(), @@ -157,11 +166,11 @@ protected static function textFieldOptions(): array ->visible(fn ($get) => $get('field_type') === 'number') ->schema([ Forms\Components\TextInput::make('max_value') - ->label('Maksimum Değer') + ->label(trans('filament-form-maker::form-maker.resources.builder.options.text_field.max_value')) ->type('number') ->nullable(), Forms\Components\TextInput::make('min_value') - ->label('Minimum Değer') + ->label(trans('filament-form-maker::form-maker.resources.builder.options.text_field.min_value')) ->type('number') ->nullable(), ]), @@ -172,34 +181,31 @@ protected static function textFieldOptions(): array protected static function getFileFieldOptions(): array { return [ - Forms\Components\Section::make('Dosya Alanı Ayarları') + Forms\Components\Section::make(trans('filament-form-maker::form-maker.resources.builder.options.file_field.title')) ->statePath('options') ->collapsed() ->schema([ Forms\Components\TextInput::make('max_size') - ->label('Maksimum Dosya Boyutu') + ->label(trans('filament-form-maker::form-maker.resources.builder.options.file_field.max_size')) ->type('number') ->default(5120) - ->hint('KB cinsinden') + ->hint(trans('filament-form-maker::form-maker.resources.builder.options.file_field.hint')) ->suffix('KB') ->nullable(), Forms\Components\Select::make('accepted_file_types') - ->label('Kabul Edilen Dosya Türleri') + ->label(trans('filament-form-maker::form-maker.resources.builder.options.file_field.accepted_file_types')) ->options([ 'application/pdf' => 'PDF', 'application/msword' => 'Word', 'application/vnd.ms-excel' => 'Excel', 'application/vnd.ms-powerpoint' => 'PowerPoint', 'application/zip' => 'Zip', - 'image/*' => 'Resim', + 'image/*' => trans('filament-form-maker::form-maker.resources.builder.options.file_field.image'), ]) ->native(false) ->searchable() ->multiple() ->required(), - Forms\Components\TextInput::make('helper_text') - ->label('Yardımcı Metin') - ->nullable(), ]), ]; } @@ -214,33 +220,36 @@ protected static function getConditionalFieldOptions($getFields): Forms\Componen }); } - return Forms\Components\Section::make('Koşullu Görünürlük') + return Forms\Components\Section::make(trans('filament-form-maker::form-maker.resources.builder.options.visibility.title')) ->statePath('options.visibility') ->collapsed() ->schema([ Forms\Components\Toggle::make('active') ->live() - ->label('Koşullu Görünürlük Aktif'), + ->label(trans('filament-form-maker::form-maker.resources.builder.options.visibility.active')), Forms\Components\Select::make('fieldId') - ->label('Koşul Bağlanacak Alan:') + ->label(trans('filament-form-maker::form-maker.resources.builder.options.visibility.fieldId')) ->live() ->searchable(false) ->visible(fn ($get): bool => ! empty($get('active'))) ->required(fn ($get): bool => ! empty($get('active'))) ->native(false) ->searchable() - ->options(optional($getFields)->where('type', 'select')->pluck('name', 'options.fieldId')->toArray()) + ->options(optional($getFields)->select('name', 'options', 'type')->mapWithKeys(function ($field) { + return [$field['options']['fieldId'] => $field['name']]; + })->toArray()) ->afterStateUpdated(fn ($get, $set) => $set('values', null)), Forms\Components\Select::make('values') - ->label('Görünürlük Değeri:') + ->label(trans('filament-form-maker::form-maker.resources.builder.options.visibility.values')) ->live() ->searchable(false) - ->visible(fn ($get): bool => ! empty($get('active'))) - ->helperText('Eğer herhangi bir değer seçildiği takdirde görünür olmasını istiyorsanız bu alanı boş bırakın.') + ->visible(fn ($get): bool => ! empty($get('active')) && optional($getFields)->where('options.fieldId', $get('fieldId'))->where('type', 'select')->isNotEmpty()) + ->helperText(trans('filament-form-maker::form-maker.resources.builder.options.visibility.values_helper_text')) ->native(false) ->searchable() + ->multiple() ->options(function ($get) use ($getFields) { $getRelated = $getFields->where('options.fieldId', $get('fieldId'))->where('type', 'select')->first();