PluginProbe
The Innovative Form Builder – IvyForms / 0.2.1
The Innovative Form Builder – IvyForms v0.2.1
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 0.2.1, at backend/src/Factory/Form/FormFactory.php

95 lines 2.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 © TMS-Plugins. All rights reserved.
5 * @licence See LICENCE.md for license details.
6 */
7
8 namespace IvyForms\Factory\Form;
9
10 // phpcs:disable PSR1.Files.SideEffects
11 if (!defined('ABSPATH')) {
12 exit; // Exit if accessed directly
13 }
14
15 use IvyForms\Common\Exceptions\ValidationException;
16 use IvyForms\Entity\Form\Form as FormEntity;
17 use IvyForms\ValueObjects\Form\Form;
18
19 /**
20 * Class FormFactory
21 *
22 * @package IvyForms\Factory\Form
23 */
24 class FormFactory
25 {
26 /**
27 * @param array<string, mixed> $data
28 *
29 * @retrun FormEntity
30 *
31 * @throws ValidationException
32 */
33 public static function create(array $data): FormEntity
34 {
35 $settings = isset($data['settings']) ? json_decode($data['settings'], true) : [];
36
37 if (!empty($settings)) {
38 $data['showTitle'] = $settings['showTitle'] ?? true;
39 $data['showDescription'] = $settings['showDescription'] ?? false;
40 }
41
42 $formObject = new Form(
43 $data['id'] ?? 0,
44 $data['name'] ?? '',
45 $data['author'] ?? '',
46 $data['starred'] ?? false,
47 $data['published'] ?? true,
48 $data['description'] ?? '',
49 $data['showTitle'] ?? true,
50 $data['showDescription'] ?? false,
51 $data['fields'] ?? [],
52 );
53
54 $form = new FormEntity($formObject);
55
56 if (isset($data['id'])) {
57 $form->setId($data['id']);
58 }
59
60 if (isset($data['name'])) {
61 $form->setName($data['name']);
62 }
63
64 if (isset($data['author'])) {
65 $form->setAuthor($data['author']);
66 }
67
68 if (isset($data['starred'])) {
69 $form->setStarred($data['starred']);
70 }
71
72 if (isset($data['published'])) {
73 $form->setPublished($data['published']);
74 }
75
76 if (isset($data['description'])) {
77 $form->setDescription($data['description']);
78 }
79
80 if (isset($data['fields'])) {
81 $form->setFields($data['fields']);
82 }
83
84 if (isset($data['showTitle'])) {
85 $form->setTitleVisible($data['showTitle']);
86 }
87
88 if (isset($data['showDescription'])) {
89 $form->setDescriptionVisible($data['showDescription']);
90 }
91
92 return $form;
93 }
94 }
95