PluginProbe
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder / 5.2.9
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder v5.2.9
6.2.14 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 All 196 releases
fluentform / app / Modules / Form / FormFieldsParser.php

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

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