From 4718535fdacb359bd27136c2901deacff1a1864e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=9Cmit=20Tun=C3=A7?= Date: Sat, 1 Nov 2025 15:52:22 -0300 Subject: [PATCH] Update view component usage in template forms: Replaced `extraAttributes` with `viewData` method in HeaderTemplateForm, FooterTemplateForm, and SectionTemplateForm schemas to align with Filament 4.x standards. Enhanced the template-preview Blade component to utilize local variables for type and field name, improving data handling and consistency. --- .cursorrules | 32 +++++++++++++++++++ .../Schemas/FooterTemplateForm.php | 6 ++-- .../Schemas/HeaderTemplateForm.php | 6 ++-- .../Schemas/SectionTemplateForm.php | 6 ++-- .../components/template-preview.blade.php | 5 ++- 5 files changed, 43 insertions(+), 12 deletions(-) diff --git a/.cursorrules b/.cursorrules index 6c40fa6..9393cb8 100644 --- a/.cursorrules +++ b/.cursorrules @@ -108,6 +108,7 @@ use Filament\Schemas\Components\Grid; // ✅ Doğru use Filament\Schemas\Components\Fieldset; // ✅ Doğru use Filament\Schemas\Components\Flex; // ✅ Doğru use Filament\Schemas\Components\Group; // ✅ Doğru - Schema içinde gruplamak için +use Filament\Schemas\Components\View; // ✅ Doğru - Blade view component // Tabs components (ÖNEMLİ: Schemas namespace!) use Filament\Schemas\Components\Tabs; // ✅ Doğru @@ -224,6 +225,37 @@ $table - `Filament\Forms\Components\Group` diye bir class **YOK**. Schema içinde gruplamak için `Filament\Schemas\Components\Group` kullan! - `Filament\Forms\Get` ve `Filament\Forms\Set` diye class'lar **YOK**. `Filament\Schemas\Components\Utilities\Get` ve `Filament\Schemas\Components\Utilities\Set` kullan! +#### **Filament 4.x VIEW COMPONENT KULLANIM KURALLARI (KRİTİK!):** + +View component'ine veri iletmek için **sadece `viewData()` metodu** kullanılır: + +```php +use Filament\Schemas\Components\View; + +// ✅ DOĞRU - viewData() ile veri gönder +View::make('components.template-preview') + ->viewData([ + 'type' => 'header', + 'fieldName' => 'html_content', + ]) + ->columnSpanFull(); + +// ❌ YANLIŞ - with() metodu ÇALIŞMAZ! +View::make('components.template-preview') + ->with([...]) // ❌ Bu metod View component'inde YOK! + +// ❌ YANLIŞ - extraAttributes() sadece HTML attribute'leri için +View::make('components.template-preview') + ->extraAttributes([ + 'data-type' => 'header', // ❌ Bu view'e değişken olarak GİTMEZ! + ]) +``` + +**Özet:** +- ✅ `->viewData([...])` → Blade view'e değişken gönderir +- ❌ `->with([...])` → View component'inde bu metod YOK +- ❌ `->extraAttributes([...])` → Sadece HTML attribute'leri için, view değişkenleri için DEĞİL + #### **Filament 4.x REPEATER KULLANIM KURALLARI (KRİTİK!):** Repeater component'ı JSON array formatında tekrarlanan form component'leri oluşturmak için kullanılır. diff --git a/app/Filament/Admin/Resources/FooterTemplates/Schemas/FooterTemplateForm.php b/app/Filament/Admin/Resources/FooterTemplates/Schemas/FooterTemplateForm.php index 42c0531..e31d58e 100644 --- a/app/Filament/Admin/Resources/FooterTemplates/Schemas/FooterTemplateForm.php +++ b/app/Filament/Admin/Resources/FooterTemplates/Schemas/FooterTemplateForm.php @@ -43,9 +43,9 @@ class FooterTemplateForm // Preview Component - placed after editor View::make('components.template-preview') - ->extraAttributes([ - 'data-type' => 'footer', - 'data-field-name' => 'html_content', + ->viewData([ + 'type' => 'footer', + 'fieldName' => 'html_content', ]) ->columnSpanFull(), diff --git a/app/Filament/Admin/Resources/HeaderTemplates/Schemas/HeaderTemplateForm.php b/app/Filament/Admin/Resources/HeaderTemplates/Schemas/HeaderTemplateForm.php index 47cbba5..ec63639 100644 --- a/app/Filament/Admin/Resources/HeaderTemplates/Schemas/HeaderTemplateForm.php +++ b/app/Filament/Admin/Resources/HeaderTemplates/Schemas/HeaderTemplateForm.php @@ -42,9 +42,9 @@ class HeaderTemplateForm // Preview Component - placed after editor View::make('components.template-preview') - ->extraAttributes([ - 'data-type' => 'header', - 'data-field-name' => 'html_content', + ->viewData([ + 'type' => 'header', + 'fieldName' => 'html_content', ]) ->columnSpanFull(), diff --git a/app/Filament/Admin/Resources/SectionTemplates/Schemas/SectionTemplateForm.php b/app/Filament/Admin/Resources/SectionTemplates/Schemas/SectionTemplateForm.php index ac01695..f700df0 100644 --- a/app/Filament/Admin/Resources/SectionTemplates/Schemas/SectionTemplateForm.php +++ b/app/Filament/Admin/Resources/SectionTemplates/Schemas/SectionTemplateForm.php @@ -42,9 +42,9 @@ class SectionTemplateForm // Preview Component - placed after editor View::make('components.template-preview') - ->extraAttributes([ - 'data-type' => 'section', - 'data-field-name' => 'html_content', + ->viewData([ + 'type' => 'section', + 'fieldName' => 'html_content', ]) ->columnSpanFull(), diff --git a/resources/views/components/template-preview.blade.php b/resources/views/components/template-preview.blade.php index 095164f..e8014d4 100644 --- a/resources/views/components/template-preview.blade.php +++ b/resources/views/components/template-preview.blade.php @@ -1,9 +1,8 @@ @php $previewUrl = route('template.preview'); - $type = $attributes->get('data-type') ?? 'section'; - $fieldName = $attributes->get('data-field-name') ?? 'html_content'; + $type = $type ?? 'section'; + $fieldName = $fieldName ?? 'html_content'; @endphp -