PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.32.1
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.32.1
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
formidable / classes / factories / FrmFieldFactory.php

FrmFieldFactory.php in Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More 6.32.1, at classes/factories/FrmFieldFactory.php

145 lines 3.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 die( 'You are not allowed to call this page directly.' );
4 }
5
6 /**
7 * @since 2.03.05
8 */
9 class FrmFieldFactory {
10
11 /**
12 * Create an instance of an FrmFieldValueSelector object
13 *
14 * @since 2.03.05
15 *
16 * @param int $field_id
17 * @param array $args
18 *
19 * @return FrmFieldValueSelector
20 */
21 public static function create_field_value_selector( $field_id, $args ) {
22 $selector = null;
23
24 if ( $field_id > 0 ) {
25 $selector = apply_filters( 'frm_create_field_value_selector', $selector, $field_id, $args );
26 }
27
28 if ( ! is_object( $selector ) ) {
29 return new FrmFieldValueSelector( $field_id, $args );
30 }
31
32 return $selector;
33 }
34
35 /**
36 * @since 3.0
37 *
38 * @param array|object $field
39 *
40 * @return FrmFieldType
41 */
42 public static function get_field_factory( $field ) {
43 if ( is_object( $field ) ) {
44 $field_info = self::get_field_object( $field );
45 } elseif ( ! empty( $field['id'] ) ) {
46 $field_info = self::get_field_object( $field['id'] );
47 } else {
48 $field_info = self::get_field_type( $field['type'], $field );
49 }
50
51 return $field_info;
52 }
53
54 /**
55 * @param int|object|string $field
56 *
57 * @return FrmFieldType
58 */
59 public static function get_field_object( $field ) {
60 if ( ! is_object( $field ) ) {
61 $field = FrmField::getOne( $field );
62 }
63
64 return self::get_field_type( $field->type, $field );
65 }
66
67 /**
68 * @since 3.0
69 *
70 * @param string $field_type
71 * @param array|int|object $field
72 *
73 * @return FrmFieldType
74 */
75 public static function get_field_type( $field_type, $field = 0 ) {
76 $class = self::get_field_type_class( $field_type );
77 return $class ? new $class( $field, $field_type ) : new FrmFieldDefault( $field, $field_type );
78 }
79
80 /**
81 * @since 3.0
82 *
83 * @param string $field_type
84 *
85 * @return string
86 */
87 private static function get_field_type_class( $field_type ) {
88 $type_classes = array(
89 'text' => 'FrmFieldText',
90 'textarea' => 'FrmFieldTextarea',
91 'select' => 'FrmFieldSelect',
92 'radio' => 'FrmFieldRadio',
93 'checkbox' => 'FrmFieldCheckbox',
94 'number' => 'FrmFieldNumber',
95 'phone' => 'FrmFieldPhone',
96 'url' => 'FrmFieldUrl',
97 'website' => 'FrmFieldUrl',
98 'email' => 'FrmFieldEmail',
99 'user_id' => 'FrmFieldUserID',
100 'html' => 'FrmFieldHTML',
101 'hidden' => 'FrmFieldHidden',
102 'captcha' => 'FrmFieldCaptcha',
103 'name' => 'FrmFieldName',
104 'credit_card' => 'FrmFieldCreditCard',
105 // Submit button field.
106 FrmSubmitHelper::FIELD_TYPE => 'FrmFieldSubmit',
107 FrmFieldGdprHelper::FIELD_TYPE => FrmFieldGdprHelper::get_gdpr_field_class( $field_type ),
108 'product' => 'FrmFieldProduct',
109 'quantity' => 'FrmFieldQuantity',
110 'total' => 'FrmFieldTotal',
111 );
112
113 $class = $type_classes[ $field_type ] ?? '';
114
115 return apply_filters( 'frm_get_field_type_class', $class, $field_type );
116 }
117
118 /**
119 * @since 3.0
120 *
121 * @param string $type
122 *
123 * @return mixed
124 */
125 public static function field_has_html( $type ) {
126 $has_html = self::field_has_property( $type, 'has_html' );
127
128 // This hook is here for reverse compatibility since 3.0
129 return apply_filters( 'frm_show_custom_html', $has_html, $type );
130 }
131
132 /**
133 * @since 3.0
134 *
135 * @param string $type
136 * @param string $property
137 *
138 * @return mixed
139 */
140 public static function field_has_property( $type, $property ) {
141 $field = self::get_field_type( $type );
142 return $field->{$property};
143 }
144 }
145