PluginProbe
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder / 4.3.17
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder v4.3.17
6.2.13 6.2.12 6.2.10 6.2.11 6.2.9 6.2.8 6.2.7 6.2.6 6.2.5 6.2.4 6.2.3 6.2.2 3.6.22 3.6.31 3.6.40 3.6.41 3.6.42 3.6.50 3.6.51 3.6.60 3.6.61 3.6.62 3.6.64 3.6.65 3.6.66 All 195 releases
fluentform / app / Modules / Form / FormFieldsParser.php

FormFieldsParser.php in Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder 4.3.17, at app/Modules/Form/FormFieldsParser.php

130 lines 4.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentForm\App\Modules\Form;
4
5 use FluentForm\App\Services\Parser\Form as FormParser;
6
7 /**
8 * Available methods
9 *
10 * @method array getShortCodeInputs(\stdClass $form, array $with = ['admin_label'])
11 * @method array getValidations(\stdClass $form, array $inputs, array $fields = [])
12 * @method array getElement(\stdClass $form, string|array $name, array $with = [])
13 * @method boolean hasElement(\stdClass $form, string $name)
14 * @method boolean hasPaymentFields(\stdClass $form)
15 * @method array getPaymentFields(\stdClass $form, $with = [])
16 * @method array getPaymentInputFields(\stdClass $form, $with = [])
17 * @method array getAttachmentInputFields(\stdClass $form, $with = [])
18 * @method boolean hasRequiredFields(\stdClass $form, array $fields)
19 * @method array getInputsByElementTypes(\stdClass $form, array $elements, array $with = [])
20 * @method array|null getField(\stdClass $form, string|array $element, string|array $attribute, array $with = [])
21 */
22 class FormFieldsParser
23 {
24 protected static $forms = [];
25
26 protected static $formsWith = [];
27
28 public static function maybeResetForm($form, $with)
29 {
30 if (!is_object($form) && is_numeric($form)) {
31 $form = wpFluent()->table('fluentform_forms')->find($form);
32 }
33
34 if (isset(static::$formsWith[$form->id]) && array_diff(static::$formsWith[$form->id], $with)) {
35 static::$forms[$form->id] = [];
36 }
37 static::$formsWith[$form->id] = $with;
38 }
39
40 public static function getFields($form, $asArray = false)
41 {
42 return static::parse('fields', $form, $asArray);
43 }
44
45 public static function getInputs($form, $with = [])
46 {
47 static::maybeResetForm($form, $with);
48 return static::parse('inputs', $form, $with);
49 }
50
51 public static function getEntryInputs($form, $with = ['admin_label', 'raw'])
52 {
53 static::maybeResetForm($form, $with);
54 return static::parse('entry_inputs', $form, $with);
55 }
56
57 public static function parse($key, $form, $with)
58 {
59 if (!is_object($form) && is_numeric($form)) {
60 $form = wpFluent()->table('fluentform_forms')->find($form);
61 }
62
63 if (!isset(static::$forms[$form->id])) {
64 static::$forms[$form->id] = [];
65 }
66
67 if (!isset(static::$forms[$form->id][$key])) {
68 $parser = new FormParser($form);
69 $method = str_replace(' ', '', ucwords(str_replace('_', ' ', $key)));
70
71 static::$forms[$form->id][$key] = $parser->{'get' . $method}($with);
72 }
73
74 return static::$forms[$form->id][$key];
75 }
76
77 public static function getAdminLabels($form, $fields = [])
78 {
79 if (!isset(static::$forms[$form->id])) {
80 static::$forms[$form->id] = [];
81 }
82
83 if (!isset(static::$forms[$form->id]['admin_labels'])) {
84 $parser = new FormParser($form);
85 static::$forms[$form->id]['admin_labels'] = $parser->getAdminLabels($fields);
86 }
87
88 return static::$forms[$form->id]['admin_labels'];
89 }
90
91 /**
92 * Deligate dynamic static method calls to FormParser method.
93 * And set the result to the store before returning to dev.
94 *
95 * @param string $method
96 * @param array $parameters
97 *
98 * @return mixed
99 */
100 public static function __callStatic($method, $parameters)
101 {
102 // The first item of the parameters is expected to contain the form object.
103 $form = array_shift($parameters);
104
105 $forceFreshValue = [
106 'getField',
107 'getElement',
108 'hasElement',
109 'getInputsByElementTypes',
110 ];
111
112 // If the store doesn't have the requested result we'll
113 // deletegate the method call to the Parser method.
114 // Set the store before returning it to the dev.
115 if (in_array($method, $forceFreshValue) || !isset(static::$forms[$form->id][$method])) {
116 $parser = new FormParser($form);
117
118 static::$forms[$form->id][$method] = call_user_func_array([$parser, $method], $parameters);
119 }
120
121 return static::$forms[$form->id][$method];
122 }
123
124 public static function resetData()
125 {
126 static::$forms = [];
127 static::$formsWith = [];
128 }
129 }
130