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.
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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(),
|
||||
|
||||
|
||||
@@ -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(),
|
||||
|
||||
|
||||
@@ -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(),
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
<div
|
||||
x-data="templatePreview(@js($previewUrl), @js($type), @js($fieldName))"
|
||||
class="template-preview-wrapper w-full"
|
||||
|
||||
Reference in New Issue
Block a user