PluginProbe
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder / 3.6.21
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder v3.6.21
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 3.6.21, at app/Modules/Form/FormFieldsParser.php

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