PluginProbe
The Innovative Form Builder – IvyForms / 1.0
The Innovative Form Builder – IvyForms v1.0
1.5.1 1.5 1.4.1 1.4 trunk 0.1.2 0.2 0.2.1 0.3 0.3.1 0.4 0.5 0.6 0.6.1 0.6.1-backup 0.6.1.1 0.7 0.8 0.8.1 0.8.2 0.9 0.9.1 1.0 1.1 1.1.1 All 27 releases
ivyforms / backend / src / Factory / Form / FormFactory.php

FormFactory.php in The Innovative Form Builder – IvyForms 1.0, at backend/src/Factory/Form/FormFactory.php

112 lines 3.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * @copyright © Melograno Venture Studio. All rights reserved.
5 * @licence See LICENCE.md for license details.
6 */
7
8 namespace IvyForms\Factory\Form;
9
10 use IvyForms\Common\Exceptions\ValidationException;
11 use IvyForms\Common\Helpers\Helper;
12 use IvyForms\Entity\Form\Form as FormEntity;
13 use IvyForms\ValueObjects\Form\Form;
14 use IvyForms\ValueObjects\Form\IntegrationSettings;
15 use IvyForms\ValueObjects\Form\StyleSettings;
16 use IvyForms\Services\Translations\BackendStrings;
17
18 /**
19 * Class FormFactory
20 *
21 * @package IvyForms\Factory\Form
22 */
23 class FormFactory
24 {
25 /**
26 * @param array<string, mixed> $data
27 *
28 * @return FormEntity
29 *
30 * @throws ValidationException
31 */
32 public static function create(array $data): FormEntity
33 {
34 $settings = isset($data['settings']) ? json_decode($data['settings'], true) : [];
35 $integrationSettings = Helper::parseToArray($data['integrationSettings']);
36 $rawStyleSettings = isset($data['styleSettings']) ? Helper::parseToArray($data['styleSettings']) : null;
37 $styleSettings = new StyleSettings(is_array($rawStyleSettings) ? $rawStyleSettings : null);
38
39 if (!empty($settings)) {
40 $data['showTitle'] = $settings['showTitle'] ?? true;
41 $data['showDescription'] = $settings['showDescription'] ?? false;
42 $data['storeEntries'] = !isset($settings['storeEntries']) || (bool)$settings['storeEntries'];
43 $data['formActionButtons'] = $settings['formActionButtons'] ?? [
44 'submitButtonSettings' => [
45 'label' => BackendStrings::getCommonStrings()['submit'],
46 'position' => 'default'
47 ]
48 ];
49 }
50
51 $formObject = new Form(
52 $data['id'] ?? 0,
53 $data['name'] ?? '',
54 $data['author'] ?? '',
55 $data['starred'] ?? false,
56 $data['published'] ?? true,
57 $data['description'] ?? '',
58 $data['showTitle'] ?? true,
59 $data['showDescription'] ?? false,
60 isset($data['storeEntries']) ? (bool)$data['storeEntries'] : true,
61 $data['fields'] ?? [],
62 new IntegrationSettings($integrationSettings),
63 $styleSettings,
64 $data['formActionButtons']
65 );
66
67 $form = new FormEntity($formObject);
68
69 if (isset($data['id'])) {
70 $form->setId($data['id']);
71 }
72
73 if (isset($data['name'])) {
74 $form->setName($data['name']);
75 }
76
77 if (isset($data['author'])) {
78 $form->setAuthor($data['author']);
79 }
80
81 if (isset($data['starred'])) {
82 $form->setStarred($data['starred']);
83 }
84
85 if (isset($data['published'])) {
86 $form->setPublished($data['published']);
87 }
88
89 if (isset($data['description'])) {
90 $form->setDescription($data['description']);
91 }
92
93 if (isset($data['fields'])) {
94 $form->setFields($data['fields']);
95 }
96
97 if (isset($data['showTitle'])) {
98 $form->setTitleVisible($data['showTitle']);
99 }
100
101 if (isset($data['showDescription'])) {
102 $form->setDescriptionVisible($data['showDescription']);
103 }
104
105 if (isset($data['storeEntries'])) {
106 $form->setStoreEntries($data['storeEntries']);
107 }
108
109 return $form;
110 }
111 }
112