|
|
@@ -4,6 +4,7 @@ namespace App\Filament\Resources;
|
|
4
|
4
|
|
|
5
|
5
|
use App\Filament\Resources\EsgResource\Pages;
|
|
6
|
6
|
use App\Models\Esg;
|
|
|
7
|
+use Filament\Forms\Components\Fieldset;
|
|
7
|
8
|
use Filament\Forms\Components\FileUpload;
|
|
8
|
9
|
use Filament\Forms\Components\Grid;
|
|
9
|
10
|
use Filament\Forms\Components\Group;
|
|
|
@@ -26,6 +27,8 @@ use Filament\Tables\Columns\TextColumn;
|
|
26
|
27
|
use Filament\Tables\Table;
|
|
27
|
28
|
use Illuminate\Database\Eloquent\Builder;
|
|
28
|
29
|
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
|
|
30
|
+use Malzariey\FilamentLexicalEditor\Enums\ToolbarItem;
|
|
|
31
|
+use Malzariey\FilamentLexicalEditor\FilamentLexicalEditor;
|
|
29
|
32
|
use SolutionForest\FilamentTranslateField\Forms\Component\Translate;
|
|
30
|
33
|
use Str;
|
|
31
|
34
|
|
|
|
@@ -40,6 +43,15 @@ class EsgResource extends Resource
|
|
40
|
43
|
|
|
41
|
44
|
public static function form(Form $form): Form
|
|
42
|
45
|
{
|
|
|
46
|
+ $editor_toolbar= [
|
|
|
47
|
+ ToolbarItem::UNDO, ToolbarItem::REDO, ToolbarItem::NORMAL,
|
|
|
48
|
+ ToolbarItem::H2, ToolbarItem::H3, ToolbarItem::H4, ToolbarItem::H5,
|
|
|
49
|
+ ToolbarItem::BULLET, ToolbarItem::NUMBERED, ToolbarItem::FONT_SIZE,
|
|
|
50
|
+ ToolbarItem::BOLD, ToolbarItem::ITALIC, ToolbarItem::UNDERLINE,
|
|
|
51
|
+ ToolbarItem::LINK, ToolbarItem::TEXT_COLOR, ToolbarItem::BACKGROUND_COLOR,
|
|
|
52
|
+ ToolbarItem::SUBSCRIPT, ToolbarItem::LOWERCASE, ToolbarItem::DIVIDER,
|
|
|
53
|
+ ToolbarItem::UPPERCASE, ToolbarItem::CLEAR, ToolbarItem::HR
|
|
|
54
|
+ ];
|
|
43
|
55
|
return $form
|
|
44
|
56
|
->schema([
|
|
45
|
57
|
//
|
|
|
@@ -105,18 +117,19 @@ class EsgResource extends Resource
|
|
105
|
117
|
5 => "影片",
|
|
106
|
118
|
])->label("")->default(1)->Live(),
|
|
107
|
119
|
Group::make()->schema([
|
|
108
|
|
- Translate::make()->schema(fn (string $locale) => [
|
|
109
|
|
- RichEditor::make('content.text_content')
|
|
110
|
|
- ->fileAttachmentsDirectory('attachments')
|
|
111
|
|
- ->fileAttachmentsVisibility('private')
|
|
112
|
|
- ->disableToolbarButtons(['attachFiles'])
|
|
113
|
|
- ->required($locale == "zh_TW")
|
|
114
|
|
- ->validationMessages([
|
|
115
|
|
- 'required' => '請填寫文字內容',
|
|
116
|
|
- ]),
|
|
117
|
|
- ])
|
|
118
|
|
- ->locales(["zh_TW", "en"])
|
|
119
|
|
- ->id(fn ($get) => "para_text_" . $get('item_key')),
|
|
|
120
|
+ Section::make('純文字設定')->schema([
|
|
|
121
|
+ FilamentLexicalEditor::make('content.text_content_tw')
|
|
|
122
|
+ ->label('中文')
|
|
|
123
|
+ ->id(fn ($get) => "text_content_tw_" . $get('item_key') . "_" . uniqid())
|
|
|
124
|
+ ->enabledToolbars($editor_toolbar)
|
|
|
125
|
+ ->required()
|
|
|
126
|
+ ->columnSpanFull(),
|
|
|
127
|
+ FilamentLexicalEditor::make('content.text_content_en')
|
|
|
128
|
+ ->label('English')
|
|
|
129
|
+ ->id(fn ($get) => "text_content_en_" . $get('item_key') . "_" . uniqid())
|
|
|
130
|
+ ->enabledToolbars($editor_toolbar)
|
|
|
131
|
+ ->columnSpanFull(),
|
|
|
132
|
+ ]),
|
|
120
|
133
|
])->visible(fn (Get $get):bool => $get("type") == 1),
|
|
121
|
134
|
Group::make()->schema([
|
|
122
|
135
|
Section::make('區塊文字設定')->schema([
|
|
|
@@ -130,18 +143,18 @@ class EsgResource extends Resource
|
|
130
|
143
|
$component->state(Str::random());
|
|
131
|
144
|
}
|
|
132
|
145
|
}),
|
|
133
|
|
- // 多語系內容
|
|
134
|
|
- Translate::make()->schema(fn (string $locale) => [
|
|
135
|
|
- RichEditor::make('block_content')
|
|
136
|
|
- ->disableToolbarButtons(['attachFiles'])
|
|
137
|
|
- ->required($locale == "zh_TW")
|
|
138
|
|
- ->validationMessages([
|
|
139
|
|
- 'required' => '請填寫文字內容',
|
|
140
|
|
- ]),
|
|
141
|
|
- ])
|
|
142
|
|
- ->locales(["zh_TW", "en"])
|
|
143
|
|
- ->id(fn ($get) => "text_block_" . $get('block_item_key')),
|
|
144
|
|
-
|
|
|
146
|
+ FilamentLexicalEditor::make('block_content_tw')
|
|
|
147
|
+ ->label('繁體中文內容')
|
|
|
148
|
+ ->id(fn ($get) => "block_content_tw_" . $get('block_item_key') . "_" . uniqid())
|
|
|
149
|
+ ->enabledToolbars($editor_toolbar)
|
|
|
150
|
+ ->required()
|
|
|
151
|
+ ->live(onBlur: true)
|
|
|
152
|
+ ->columnSpanFull(),
|
|
|
153
|
+ FilamentLexicalEditor::make('block_content_en')
|
|
|
154
|
+ ->label('English Content')
|
|
|
155
|
+ ->id(fn ($get) => "block_content_en_" . $get('block_item_key') . "_" . uniqid())
|
|
|
156
|
+ ->enabledToolbars($editor_toolbar)
|
|
|
157
|
+ ->columnSpanFull(),
|
|
145
|
158
|
])
|
|
146
|
159
|
->label("")
|
|
147
|
160
|
->addActionLabel('增加區塊')
|
|
|
@@ -241,79 +254,136 @@ class EsgResource extends Resource
|
|
241
|
254
|
$component->state(Str::random());
|
|
242
|
255
|
}
|
|
243
|
256
|
}),
|
|
244
|
|
- Translate::make()->schema(fn (string $locale) => [
|
|
245
|
|
- Grid::make(1) // 改用 Grid 來支援動態 columns
|
|
246
|
|
- ->schema([
|
|
247
|
|
- Radio::make('align1')
|
|
248
|
|
- ->label('對齊')
|
|
249
|
|
- ->options([
|
|
250
|
|
- 1 => '置左', // 改為數字鍵值
|
|
251
|
|
- 2 => '置中',
|
|
252
|
|
- 3 => '置右'
|
|
253
|
|
- ])
|
|
254
|
|
- ->default(1),
|
|
255
|
|
- RichEditor::make('col1')
|
|
256
|
|
- ->label('第1欄')
|
|
257
|
|
- ->disableToolbarButtons(['attachFiles'])
|
|
258
|
|
- ->required($locale == "zh_TW")
|
|
259
|
|
- ->validationMessages([
|
|
260
|
|
- 'required' => '請填寫',
|
|
261
|
|
- ]),
|
|
262
|
|
- // TextInput::make('col2')->label('第2欄')->required(),
|
|
263
|
|
- Radio::make('align2')
|
|
|
257
|
+ Grid::make(1) // 改用 Grid 來支援動態 columns
|
|
|
258
|
+ ->schema([
|
|
|
259
|
+ Section::make("第一欄")->schema([
|
|
|
260
|
+ Fieldset::make('中文')->schema([
|
|
|
261
|
+ Radio::make('align1_tw')
|
|
|
262
|
+ ->label('對齊')
|
|
|
263
|
+ ->options([
|
|
|
264
|
+ 1 => '置左', // 改為數字鍵值
|
|
|
265
|
+ 2 => '置中',
|
|
|
266
|
+ 3 => '置右'
|
|
|
267
|
+ ])
|
|
|
268
|
+ ->default(1)->inline(),
|
|
|
269
|
+ FilamentLexicalEditor::make('col1_tw')
|
|
|
270
|
+ ->id(fn ($get) => "col1_tw_" . $get('simple_table_rows_key') . "_" . uniqid())
|
|
|
271
|
+ ->enabledToolbars($editor_toolbar)
|
|
|
272
|
+ ->required()
|
|
|
273
|
+ ->columnSpanFull(),
|
|
|
274
|
+ ]),
|
|
|
275
|
+ Fieldset::make('英文')->schema([
|
|
|
276
|
+ Radio::make('align1_en')
|
|
264
|
277
|
->label('對齊')
|
|
265
|
278
|
->options([
|
|
266
|
279
|
1 => '置左', // 改為數字鍵值
|
|
267
|
280
|
2 => '置中',
|
|
268
|
281
|
3 => '置右'
|
|
269
|
282
|
])
|
|
|
283
|
+ ->default(1)->inline(),
|
|
|
284
|
+ FilamentLexicalEditor::make('col1_en')
|
|
|
285
|
+ ->id(fn ($get) => "col1_en_" . $get('simple_table_rows_key') . "_" . uniqid())
|
|
|
286
|
+ ->enabledToolbars($editor_toolbar)
|
|
|
287
|
+ ->columnSpanFull(),
|
|
|
288
|
+ ]),
|
|
|
289
|
+ ]),
|
|
|
290
|
+ Section::make("第二欄")->schema([
|
|
|
291
|
+ Fieldset::make('中文')->schema([
|
|
|
292
|
+ Radio::make('align2_tw')
|
|
|
293
|
+ ->label('對齊')
|
|
|
294
|
+ ->options([
|
|
|
295
|
+ 1 => '置左', // 改為數字鍵值
|
|
|
296
|
+ 2 => '置中',
|
|
|
297
|
+ 3 => '置右'
|
|
|
298
|
+ ])
|
|
|
299
|
+ ->default(1)->inline(),
|
|
|
300
|
+ FilamentLexicalEditor::make('col2_tw')
|
|
|
301
|
+ ->id(fn ($get) => "col2_tw_" . $get('simple_table_rows_key') . "_" . uniqid())
|
|
|
302
|
+ ->enabledToolbars($editor_toolbar)
|
|
|
303
|
+ ->required()
|
|
|
304
|
+ ->columnSpanFull(),
|
|
|
305
|
+ ]),
|
|
|
306
|
+ Fieldset::make('英文')->schema([
|
|
|
307
|
+ Radio::make('align2_en')
|
|
|
308
|
+ ->label('對齊')
|
|
|
309
|
+ ->options([
|
|
|
310
|
+ 1 => '置左', // 改為數字鍵值
|
|
|
311
|
+ 2 => '置中',
|
|
|
312
|
+ 3 => '置右'
|
|
|
313
|
+ ])
|
|
|
314
|
+ ->default(1)->inline(),
|
|
|
315
|
+ FilamentLexicalEditor::make('col2_en')
|
|
|
316
|
+ ->id(fn ($get) => "col2_en_" . $get('simple_table_rows_key') . "_" . uniqid())
|
|
|
317
|
+ ->enabledToolbars($editor_toolbar)
|
|
|
318
|
+ ->columnSpanFull(),
|
|
|
319
|
+ ]),
|
|
|
320
|
+ ]),
|
|
|
321
|
+ Section::make("第三欄")->schema([
|
|
|
322
|
+ Fieldset::make('中文')->schema([
|
|
|
323
|
+ Radio::make('align3_tw')
|
|
|
324
|
+ ->label('對齊')
|
|
|
325
|
+ ->options([
|
|
|
326
|
+ 1 => '置左', // 改為數字鍵值
|
|
|
327
|
+ 2 => '置中',
|
|
|
328
|
+ 3 => '置右'
|
|
|
329
|
+ ])
|
|
270
|
330
|
->default(1),
|
|
271
|
|
- RichEditor::make('col2')
|
|
272
|
|
- ->label('第2欄')
|
|
273
|
|
- ->disableToolbarButtons(['attachFiles'])
|
|
274
|
|
- ->required($locale == "zh_TW")
|
|
275
|
|
- ->validationMessages([
|
|
276
|
|
- 'required' => '請填寫',
|
|
277
|
|
- ]),
|
|
278
|
|
- Radio::make('align3')
|
|
279
|
|
- ->label('對齊')
|
|
280
|
|
- ->options([
|
|
281
|
|
- 1 => '置左', // 改為數字鍵值
|
|
282
|
|
- 2 => '置中',
|
|
283
|
|
- 3 => '置右'
|
|
284
|
|
- ])
|
|
285
|
|
- ->default(1)
|
|
286
|
|
- ->visible(fn (Get $get) => intval($get('../../../content.column_count')) >= 3),
|
|
287
|
|
- RichEditor::make('col3')
|
|
288
|
|
- ->label('第3欄')
|
|
289
|
|
- ->disableToolbarButtons(['attachFiles'])
|
|
290
|
|
- ->visible(fn (Get $get) => intval($get('../../../content.column_count')) >= 3)
|
|
291
|
|
- ->required($locale == "zh_TW" && fn (Get $get)=> intval($get("../../../content.column_count")) >= 3)
|
|
292
|
|
- ->validationMessages([
|
|
293
|
|
- 'required' => '請填寫',
|
|
|
331
|
+ FilamentLexicalEditor::make('col3_tw')
|
|
|
332
|
+ ->id(fn ($get) => "col3_tw_" . $get('simple_table_rows_key') . "_" . uniqid())
|
|
|
333
|
+ ->enabledToolbars($editor_toolbar)
|
|
|
334
|
+ ->required()
|
|
|
335
|
+ ->columnSpanFull(),
|
|
|
336
|
+ ]),
|
|
|
337
|
+ Fieldset::make('英文')->schema([
|
|
|
338
|
+ Radio::make('align3_en')
|
|
|
339
|
+ ->label('對齊')
|
|
|
340
|
+ ->options([
|
|
|
341
|
+ 1 => '置左', // 改為數字鍵值
|
|
|
342
|
+ 2 => '置中',
|
|
|
343
|
+ 3 => '置右'
|
|
|
344
|
+ ])
|
|
|
345
|
+ ->default(1)->inline(),
|
|
|
346
|
+ FilamentLexicalEditor::make('col3_en')
|
|
|
347
|
+ ->id(fn ($get) => "col3_en_" . $get('simple_table_rows_key') . "_" . uniqid())
|
|
|
348
|
+ ->enabledToolbars($editor_toolbar)
|
|
|
349
|
+ ->columnSpanFull(),
|
|
294
|
350
|
]),
|
|
295
|
|
- Radio::make('align4')
|
|
|
351
|
+ ])->visible(fn (Get $get) => intval($get('../../../content.column_count')) >= 3),
|
|
|
352
|
+ Section::make("第四欄")->schema([
|
|
|
353
|
+ Fieldset::make('中文')->schema([
|
|
|
354
|
+ Radio::make('align4_tw')
|
|
296
|
355
|
->label('對齊')
|
|
297
|
356
|
->options([
|
|
298
|
357
|
1 => '置左', // 改為數字鍵值
|
|
299
|
358
|
2 => '置中',
|
|
300
|
359
|
3 => '置右'
|
|
301
|
360
|
])
|
|
302
|
|
- ->default(1)
|
|
303
|
|
- ->visible(fn (Get $get) => intval($get('../../../content.column_count')) >= 4),
|
|
304
|
|
- RichEditor::make('col4')
|
|
305
|
|
- ->label('第4欄')
|
|
306
|
|
- ->disableToolbarButtons(['attachFiles'])
|
|
307
|
|
- ->visible(fn (Get $get) => intval($get('../../../content.column_count')) >= 4)
|
|
308
|
|
- ->required($locale == "zh_TW" && fn (Get $get)=> intval($get("../../../content.column_count")) >= 4)
|
|
309
|
|
- ->validationMessages([
|
|
310
|
|
- 'required' => '請填寫',
|
|
311
|
|
- ]),
|
|
312
|
|
- ])
|
|
313
|
|
- ->reactive() // 加入響應式
|
|
314
|
|
- ])->locales(["zh_TW", "en"]),
|
|
|
361
|
+ ->default(1)->inline(),
|
|
|
362
|
+ FilamentLexicalEditor::make('col4_tw')
|
|
|
363
|
+ ->id(fn ($get) => "col4_tw_" . $get('simple_table_rows_key') . "_" . uniqid())
|
|
|
364
|
+ ->enabledToolbars($editor_toolbar)
|
|
|
365
|
+ ->required()
|
|
|
366
|
+ ->columnSpanFull(),
|
|
|
367
|
+ ]),
|
|
|
368
|
+ Fieldset::make('英文')->schema([
|
|
|
369
|
+ Radio::make('align4_en')
|
|
|
370
|
+ ->label('對齊')
|
|
|
371
|
+ ->options([
|
|
|
372
|
+ 1 => '置左', // 改為數字鍵值
|
|
|
373
|
+ 2 => '置中',
|
|
|
374
|
+ 3 => '置右'
|
|
|
375
|
+ ])
|
|
|
376
|
+ ->default(1)->inline(),
|
|
|
377
|
+ FilamentLexicalEditor::make('col4_en')
|
|
|
378
|
+ ->id(fn ($get) => "col4_en_" . $get('simple_table_rows_key') . "_" . uniqid())
|
|
|
379
|
+ ->enabledToolbars($editor_toolbar)
|
|
|
380
|
+ ->columnSpanFull(),
|
|
|
381
|
+ ]),
|
|
|
382
|
+ ])->visible(fn (Get $get) => intval($get('../../../content.column_count')) >= 4),
|
|
|
383
|
+ ])
|
|
|
384
|
+ ->reactive() // 加入響應式
|
|
315
|
385
|
])
|
|
316
|
|
- ->id(fn ($get) => "simple_table_" . $get('simple_table_key'))
|
|
|
386
|
+ ->id(fn ($get) => "simple_table_" . $get('simple_table_rows_key'))
|
|
317
|
387
|
->addActionLabel('新增列')
|
|
318
|
388
|
->reorderableWithButtons()
|
|
319
|
389
|
->minItems(1)
|
|
|
@@ -369,6 +439,141 @@ class EsgResource extends Resource
|
|
369
|
439
|
->reorderableWithButtons()
|
|
370
|
440
|
->orderColumn('order')
|
|
371
|
441
|
->cloneable()
|
|
|
442
|
+ ->mutateRelationshipDataBeforeFillUsing(function (array $data): array {
|
|
|
443
|
+ switch($data["type"]){
|
|
|
444
|
+ case "1":
|
|
|
445
|
+ if (!empty($data["content"]['text_content'])) {
|
|
|
446
|
+ $content = is_string($data["content"]['text_content'])
|
|
|
447
|
+ ? json_decode($data["content"]['text_content'], true)
|
|
|
448
|
+ : $data["content"]['text_content'];
|
|
|
449
|
+
|
|
|
450
|
+ if (is_array($content)) {
|
|
|
451
|
+ $data["content"]['text_content_tw'] = $content['zh_TW'] ?? '';
|
|
|
452
|
+ $data["content"]['text_content_en'] = $content['en'] ?? '';
|
|
|
453
|
+ }
|
|
|
454
|
+ }
|
|
|
455
|
+ break;
|
|
|
456
|
+ case "2":
|
|
|
457
|
+ if (!empty($data["content"]['text_blocks']) && count($data["content"]['text_blocks']) > 0) {
|
|
|
458
|
+ foreach ($data["content"]['text_blocks'] as $block_index => $block){
|
|
|
459
|
+ $content = is_string($block['block_content'])
|
|
|
460
|
+ ? json_decode($block['block_content'], true)
|
|
|
461
|
+ : $block['block_content'];
|
|
|
462
|
+
|
|
|
463
|
+ if (is_array($content)) {
|
|
|
464
|
+ $data["content"]['text_blocks'][$block_index]["block_content_tw"] = $content['zh_TW'] ?? '';
|
|
|
465
|
+ $data["content"]['text_blocks'][$block_index]["block_content_en"] = $content['en'] ?? '';
|
|
|
466
|
+ }
|
|
|
467
|
+ }
|
|
|
468
|
+ }
|
|
|
469
|
+ break;
|
|
|
470
|
+ case "3":
|
|
|
471
|
+ if (!empty($data["content"]['simple_table_rows']) && count($data["content"]['simple_table_rows']) > 0) {
|
|
|
472
|
+ foreach ($data["content"]['simple_table_rows'] as $row_key => $row) {
|
|
|
473
|
+ $flatRow = [];
|
|
|
474
|
+
|
|
|
475
|
+ foreach ($row as $key => $value) {
|
|
|
476
|
+ if (is_array($value) && isset($value['zh_TW'], $value['en'])) {
|
|
|
477
|
+ // 多语言字段,分离为两个字段
|
|
|
478
|
+ $flatRow[$key . '_tw'] = $value['zh_TW'];
|
|
|
479
|
+ $flatRow[$key . '_en'] = $value['en'];
|
|
|
480
|
+ } else {
|
|
|
481
|
+ // 非多语言字段,保持原样
|
|
|
482
|
+ $flatRow[$key] = $value;
|
|
|
483
|
+ }
|
|
|
484
|
+ }
|
|
|
485
|
+
|
|
|
486
|
+ $data["content"]['simple_table_rows'][$row_key] = $flatRow;
|
|
|
487
|
+ }
|
|
|
488
|
+ }
|
|
|
489
|
+ break;
|
|
|
490
|
+ }
|
|
|
491
|
+ return $data;
|
|
|
492
|
+ })
|
|
|
493
|
+ ->mutateRelationshipDataBeforeSaveUsing(function (array $data): array {
|
|
|
494
|
+ switch($data["type"]){
|
|
|
495
|
+ case "1":
|
|
|
496
|
+ $data["content"]["text_content"] = ["zh_TW" => $data["content"]["text_content_tw"] ?? "" , "en" => $data["content"]["text_content_en"] ?? ""];
|
|
|
497
|
+ // 移除臨時的分離欄位,只保留合併的 JSON 欄位
|
|
|
498
|
+ unset($data["content"]["text_content_tw"]);
|
|
|
499
|
+ unset($data["content"]["text_content_en"]);
|
|
|
500
|
+
|
|
|
501
|
+ // 清理 HTML 標籤(如果需要)
|
|
|
502
|
+ foreach ($data['content']['text_content'] as $locale => $content) {
|
|
|
503
|
+ \Log::info($content);
|
|
|
504
|
+ \Log::info(stripslashes($content));
|
|
|
505
|
+ $data['content']['text_content'][$locale] = stripslashes($content);
|
|
|
506
|
+ }
|
|
|
507
|
+ break;
|
|
|
508
|
+ case "2":
|
|
|
509
|
+ // 確保有 text_blocks
|
|
|
510
|
+ if (!isset($data['content']['text_blocks'])) {
|
|
|
511
|
+ $data['content']['text_blocks'] = [];
|
|
|
512
|
+ }
|
|
|
513
|
+
|
|
|
514
|
+ // 處理每個文字區塊
|
|
|
515
|
+ foreach ($data['content']['text_blocks'] as $index => &$block) {
|
|
|
516
|
+ // 確保區塊有必要的欄位
|
|
|
517
|
+ $block['block_item_key'] = $block['block_item_key'] ?? Str::random();
|
|
|
518
|
+ $block['order'] = $block['order'] ?? ($index + 1);
|
|
|
519
|
+
|
|
|
520
|
+ $block["block_content"] = ["zh_TW" => $block["block_content_tw"] ?? "" , "en" => $block["block_content_en"] ?? ""];
|
|
|
521
|
+ // 移除臨時的分離欄位,只保留合併的 JSON 欄位
|
|
|
522
|
+ unset($block["block_content_tw"]);
|
|
|
523
|
+ unset($block["block_content_en"]);
|
|
|
524
|
+ // 清理區塊內容
|
|
|
525
|
+ if (isset($block['block_content'])) {
|
|
|
526
|
+ foreach ($block['block_content'] as $locale => $content) {
|
|
|
527
|
+ $block['block_content'][$locale] = stripslashes($content);
|
|
|
528
|
+ }
|
|
|
529
|
+ }
|
|
|
530
|
+ }
|
|
|
531
|
+ break;
|
|
|
532
|
+ case "3":
|
|
|
533
|
+ // 確保欄數設定
|
|
|
534
|
+ $columnCount = $data['content']['column_count'] ?? 2;
|
|
|
535
|
+
|
|
|
536
|
+ // 確保表頭存在
|
|
|
537
|
+ if (!isset($data['content']['headers'])) {
|
|
|
538
|
+ $data['content']['headers'] = ['zh_TW' => [], 'en' => []];
|
|
|
539
|
+ }
|
|
|
540
|
+
|
|
|
541
|
+ // 確保表格資料存在
|
|
|
542
|
+ if (!isset($data['content']['simple_table_rows'])) {
|
|
|
543
|
+ $data['content']['simple_table_rows'] = [];
|
|
|
544
|
+ }
|
|
|
545
|
+
|
|
|
546
|
+ // 處理表格資料,確保欄數一致
|
|
|
547
|
+ foreach ($data['content']['simple_table_rows'] as $rowIndex => &$row) {
|
|
|
548
|
+ // 確保每行都有正確的欄數
|
|
|
549
|
+ for ($i = 1; $i <= $columnCount; $i++) {
|
|
|
550
|
+ $row["col{$i}"] = ["zh_TW" => $row["col{$i}_tw"] ?? "" , "en" => $row["col{$i}_en"] ?? ""];
|
|
|
551
|
+ foreach ($row["col{$i}"] as $locale => $content) {
|
|
|
552
|
+ $row["col{$i}"][$locale] = $content;
|
|
|
553
|
+ }
|
|
|
554
|
+ unset($row["col{$i}_tw"]);
|
|
|
555
|
+ unset($row["col{$i}_en"]);
|
|
|
556
|
+ $row["align{$i}"] = ["zh_TW" => $row["align{$i}_tw"] ?? "" , "en" => $row["align{$i}_en"] ?? ""];
|
|
|
557
|
+ foreach ($row["align{$i}"] as $locale => $content) {
|
|
|
558
|
+ $row["align{$i}"][$locale] = $content;
|
|
|
559
|
+ }
|
|
|
560
|
+ unset($row["align{$i}_tw"]);
|
|
|
561
|
+ unset($row["align{$i}_en"]);
|
|
|
562
|
+ }
|
|
|
563
|
+
|
|
|
564
|
+ // 移除多餘的欄位
|
|
|
565
|
+ for ($i = $columnCount + 1; $i <= 4; $i++) {
|
|
|
566
|
+ unset($row["col{$i}_tw"]);
|
|
|
567
|
+ unset($row["col{$i}_en"]);
|
|
|
568
|
+ unset($row["align{$i}_tw"]);
|
|
|
569
|
+ unset($row["align{$i}_en"]);
|
|
|
570
|
+ }
|
|
|
571
|
+ }
|
|
|
572
|
+ break;
|
|
|
573
|
+ }
|
|
|
574
|
+ \Log::info($data);
|
|
|
575
|
+ return $data;
|
|
|
576
|
+ })
|
|
372
|
577
|
])->columnSpanFull(),
|
|
373
|
578
|
])
|
|
374
|
579
|
->columnSpanFull()
|