PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.35
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.35
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.35, at classes/factories/FrmFieldFactory.php

146 lines 3.8 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 'address' => 'FrmFieldAddress',
106 // Submit button field.
107 FrmSubmitHelper::FIELD_TYPE => 'FrmFieldSubmit',
108 FrmFieldGdprHelper::FIELD_TYPE => FrmFieldGdprHelper::get_gdpr_field_class( $field_type ),
109 'product' => 'FrmFieldProduct',
110 'quantity' => 'FrmFieldQuantity',
111 'total' => 'FrmFieldTotal',
112 );
113
114 $class = $type_classes[ $field_type ] ?? '';
115
116 return apply_filters( 'frm_get_field_type_class', $class, $field_type );
117 }
118
119 /**
120 * @since 3.0
121 *
122 * @param string $type
123 *
124 * @return mixed
125 */
126 public static function field_has_html( $type ) {
127 $has_html = self::field_has_property( $type, 'has_html' );
128
129 // This hook is here for reverse compatibility since 3.0
130 return apply_filters( 'frm_show_custom_html', $has_html, $type );
131 }
132
133 /**
134 * @since 3.0
135 *
136 * @param string $type
137 * @param string $property
138 *
139 * @return mixed
140 */
141 public static function field_has_property( $type, $property ) {
142 $field = self::get_field_type( $type );
143 return $field->{$property};
144 }
145 }
146