| @@ -1,8 +1,6 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -declare(strict_types=1); | |
| 4 | - | |
| 5 | 3 | namespace IvyForms\Services\Template; |
| 6 | 4 | |
| 7 | 5 | use IvyForms\Services\Translations\BackendStrings; |
| 8 | 6 | |
| @@ -8,62 +6,91 @@ | ||
| 8 | 6 | |
| 9 | 7 | class ContactFormTemplate |
| 10 | 8 | { |
| 11 | 9 | /** |
| 12 | - * Get the contact form template | |
| 10 | + * Get template metadata (without form_data) | |
| 13 | 11 | * |
| 14 | 12 | * @return array<string, mixed> |
| 15 | 13 | */ |
| 16 | - public static function getTemplate(): array | |
| 14 | + public static function getTemplateMeta(): array | |
| 17 | 15 | { |
| 18 | 16 | return [ |
| 19 | 17 | 'id' => 'contact_form', |
| 20 | 18 | 'name' => BackendStrings::getTemplateStrings()['contact_form'], |
| 21 | 19 | 'description' => BackendStrings::getTemplateStrings()['contact_form_desc'], |
| 22 | - 'category' => 'basic', | |
| 20 | + 'category' => 'contact-forms', | |
| 21 | + 'subcategory' => 'emergency-contact-forms', | |
| 23 | 22 | 'is_pro' => false, |
| 24 | - 'screenshot' => IVYFORMS_TEMPLATES_IMAGES_URL . 'contact-form.svg', | |
| 23 | + 'screenshot' => IVYFORMS_TEMPLATES_IMAGES_URL . 'contact-form.svg' | |
| 24 | + ]; | |
| 25 | + } | |
| 26 | + | |
| 27 | + /** | |
| 28 | + * Get the full template including form data | |
| 29 | + * | |
| 30 | + * @return array<string, mixed> | |
| 31 | + */ | |
| 32 | + public static function getTemplate(): array | |
| 33 | + { | |
| 34 | + return array_merge( | |
| 35 | + self::getTemplateMeta(), | |
| 36 | + [ | |
| 25 | 37 | 'form_data' => [ |
| 26 | - 'name' => 'Contact Form', | |
| 27 | - 'description' => 'Get in touch with us using this contact form', | |
| 38 | + 'name' => BackendStrings::getTemplateStrings()['contact_form'], | |
| 28 | 39 | 'published' => 1, |
| 29 | 40 | 'showTitle' => 1, |
| 30 | 41 | 'storeEntries' => 1, |
| 42 | + 'integrationSettings' => TemplateDefaults::getDefaultIntegrationSettings(), | |
| 31 | 43 | 'fields' => [ |
| 44 | + // Name Field - Parent | |
| 32 | 45 | [ |
| 33 | - 'id' => 'first_name', | |
| 46 | + 'id' => 1, | |
| 34 | 47 | 'fieldIndex' => 1, |
| 48 | + 'type' => 'name', | |
| 49 | + 'label' => BackendStrings::getTemplateStrings()['full_name'], | |
| 50 | + 'parentId' => null, | |
| 51 | + 'defaultValue' => '', | |
| 52 | + 'placeholder' => '', | |
| 53 | + 'required' => true, | |
| 54 | + 'readonly' => false, | |
| 55 | + 'position' => 1, | |
| 56 | + ], | |
| 57 | + // First Name - Child of Name Field | |
| 58 | + [ | |
| 59 | + 'id' => 2, | |
| 35 | 60 | 'type' => 'text', |
| 36 | - 'label' => 'First Name', | |
| 37 | - 'placeholder' => 'Enter your first name', | |
| 61 | + 'label' => BackendStrings::getTemplateStrings()['first_name'], | |
| 62 | + 'placeholder' => BackendStrings::getTemplateStrings()['enter_your_first_name'], | |
| 38 | 63 | 'required' => true, |
| 39 | - 'validation' => [ | |
| 40 | - 'required' => true, | |
| 41 | - ], | |
| 42 | - 'settings' => [ | |
| 43 | - 'css_class' => 'ivyforms-field-first-name' | |
| 44 | - ] | |
| 64 | + 'parentId' => 1, | |
| 65 | + 'fieldIndex' => 1, | |
| 66 | + 'defaultValue' => '', | |
| 67 | + 'position' => 1, | |
| 68 | + 'optionHide' => false, | |
| 69 | + 'description' => '', | |
| 70 | + 'settings' => json_encode(['nameFieldType' => 'nameField1']), | |
| 45 | 71 | ], |
| 72 | + // Last Name - Child of Name Field | |
| 46 | 73 | [ |
| 47 | - 'id' => 'last_name', | |
| 48 | - 'fieldIndex' => 2, | |
| 74 | + 'id' => 3, | |
| 49 | 75 | 'type' => 'text', |
| 50 | - 'label' => 'Last Name', | |
| 51 | - 'placeholder' => 'Enter your last name', | |
| 76 | + 'label' => BackendStrings::getTemplateStrings()['last_name'], | |
| 77 | + 'placeholder' => BackendStrings::getTemplateStrings()['enter_your_last_name'], | |
| 52 | 78 | 'required' => true, |
| 53 | - 'validation' => [ | |
| 54 | - 'required' => true, | |
| 55 | - ], | |
| 56 | - 'settings' => [ | |
| 57 | - 'css_class' => 'ivyforms-field-last-name' | |
| 58 | - ] | |
| 79 | + 'parentId' => 1, | |
| 80 | + 'fieldIndex' => 1, | |
| 81 | + 'defaultValue' => '', | |
| 82 | + 'position' => 2, | |
| 83 | + 'optionHide' => false, | |
| 84 | + 'description' => '', | |
| 85 | + 'settings' => json_encode(['nameFieldType' => 'nameField2']), | |
| 59 | 86 | ], |
| 60 | 87 | [ |
| 61 | - 'id' => 'email', | |
| 62 | - 'fieldIndex' => 3, | |
| 88 | + 'id' => 4, | |
| 89 | + 'fieldIndex' => 2, | |
| 63 | 90 | 'type' => 'email', |
| 64 | - 'label' => 'Email Address', | |
| 65 | - 'placeholder' => 'Enter your email address', | |
| 91 | + 'label' => BackendStrings::getTemplateStrings()['email_address'], | |
| 92 | + 'placeholder' => BackendStrings::getTemplateStrings()['enter_your_email_address'], | |
| 66 | 93 | 'required' => true, |
| 67 | 94 | 'validation' => [ |
| 68 | 95 | 'required' => true, |
| 69 | 96 | 'email' => true |
| @@ -69,16 +96,17 @@ | ||
| 69 | 96 | 'email' => true |
| 70 | 97 | ], |
| 71 | 98 | 'settings' => [ |
| 72 | 99 | 'css_class' => 'ivyforms-field-email' |
| 73 | - ] | |
| 100 | + ], | |
| 101 | + 'position' => 2, | |
| 74 | 102 | ], |
| 75 | 103 | [ |
| 76 | - 'id' => 'subject', | |
| 77 | - 'fieldIndex' => 4, | |
| 104 | + 'id' => 5, | |
| 105 | + 'fieldIndex' => 3, | |
| 78 | 106 | 'type' => 'text', |
| 79 | - 'label' => 'Subject', | |
| 80 | - 'placeholder' => 'What is this regarding?', | |
| 107 | + 'label' => BackendStrings::getTemplateStrings()['subject'], | |
| 108 | + 'placeholder' => BackendStrings::getTemplateStrings()['what_is_this_regarding'], | |
| 81 | 109 | 'required' => false, |
| 82 | 110 | 'validation' => [ |
| 83 | 111 | 'required' => false, |
| 84 | 112 | ], |
| @@ -83,16 +111,17 @@ | ||
| 83 | 111 | 'required' => false, |
| 84 | 112 | ], |
| 85 | 113 | 'settings' => [ |
| 86 | 114 | 'css_class' => 'ivyforms-field-subject' |
| 87 | - ] | |
| 115 | + ], | |
| 116 | + 'position' => 3, | |
| 88 | 117 | ], |
| 89 | 118 | [ |
| 90 | - 'id' => 'message', | |
| 91 | - 'fieldIndex' => 5, | |
| 119 | + 'id' => 6, | |
| 120 | + 'fieldIndex' => 4, | |
| 92 | 121 | 'type' => 'textarea', |
| 93 | - 'label' => 'Message', | |
| 94 | - 'placeholder' => 'Please enter your message here...', | |
| 122 | + 'label' => BackendStrings::getTemplateStrings()['message'], | |
| 123 | + 'placeholder' => BackendStrings::getTemplateStrings()['please_enter_your_message_here'], | |
| 95 | 124 | 'required' => false, |
| 96 | 125 | 'validation' => [ |
| 97 | 126 | 'required' => false, |
| 98 | 127 | ], |
| @@ -97,12 +126,14 @@ | ||
| 97 | 126 | 'required' => false, |
| 98 | 127 | ], |
| 99 | 128 | 'settings' => [ |
| 100 | 129 | 'css_class' => 'ivyforms-field-message' |
| 101 | - ] | |
| 130 | + ], | |
| 131 | + 'position' => 4, | |
| 102 | 132 | ] |
| 103 | 133 | ], |
| 104 | 134 | 'settings' => [] |
| 105 | 135 | ] |
| 106 | - ]; | |
| 136 | + ] | |
| 137 | + ); | |
| 107 | 138 | } |
| 108 | 139 | } |