Implement default data functionality for templates: Added 'default_data' field to HeaderTemplate, FooterTemplate, and SectionTemplate models. Enhanced TemplateService to generate dynamic fields based on this new data. Updated form schemas in template forms to include sections for default values, improving template management and usability. Added localization support for new fields in both English and Turkish.

This commit is contained in:
Ümit Tunç
2025-11-01 02:01:07 -03:00
parent c5e09296a4
commit 0d23c20f85
18 changed files with 335 additions and 23 deletions
+11 -1
View File
@@ -16,8 +16,10 @@ class TemplateService
{
/**
* Generate dynamic form fields based on template placeholders
* For default data (template forms), use dataKey = 'default_data'
* For page data (page forms), use dataKey = 'header_data' or 'footer_data'
*/
public static function generateDynamicFields($template, string $dataKey): array
public static function generateDynamicFields($template, string $dataKey, ?array $existingData = null): array
{
if (!$template) {
return [];
@@ -37,6 +39,9 @@ class TemplateService
$label = str($name)->title()->replace('_', ' ')->toString();
// Get existing value from existingData if provided
$existingValue = $existingData[$placeholder] ?? null;
$field = match($type) {
// Text Input Variants
'text' => TextInput::make("{$dataKey}.{$placeholder}")
@@ -212,6 +217,11 @@ class TemplateService
->helperText("Unknown type: {$type}"),
};
// Set default value if existingValue is provided
if ($existingValue !== null) {
$field->default($existingValue);
}
$fields[] = $field;
}