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

150 lines 3.6 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 $selector = 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 ( isset( $field['id'] ) && $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
78 if ( empty( $class ) ) {
79 $field = new FrmFieldDefault( $field, $field_type );
80 } else {
81 $field = new $class( $field, $field_type );
82 }
83
84 return $field;
85 }
86
87 /**
88 * @since 3.0
89 *
90 * @param string $field_type
91 *
92 * @return string
93 */
94 private static function get_field_type_class( $field_type ) {
95 $type_classes = array(
96 'text' => 'FrmFieldText',
97 'textarea' => 'FrmFieldTextarea',
98 'select' => 'FrmFieldSelect',
99 'radio' => 'FrmFieldRadio',
100 'checkbox' => 'FrmFieldCheckbox',
101 'number' => 'FrmFieldNumber',
102 'phone' => 'FrmFieldPhone',
103 'url' => 'FrmFieldUrl',
104 'website' => 'FrmFieldUrl',
105 'email' => 'FrmFieldEmail',
106 'user_id' => 'FrmFieldUserID',
107 'html' => 'FrmFieldHTML',
108 'hidden' => 'FrmFieldHidden',
109 'captcha' => 'FrmFieldCaptcha',
110 'name' => 'FrmFieldName',
111 'credit_card' => 'FrmFieldCreditCard',
112 // Submit button field.
113 FrmSubmitHelper::FIELD_TYPE => 'FrmFieldSubmit',
114 FrmFieldGdprHelper::FIELD_TYPE => FrmFieldGdprHelper::get_gdpr_field_class( $field_type ),
115 );
116
117 $class = $type_classes[ $field_type ] ?? '';
118
119 return apply_filters( 'frm_get_field_type_class', $class, $field_type );
120 }
121
122 /**
123 * @since 3.0
124 *
125 * @param string $type
126 *
127 * @return mixed
128 */
129 public static function field_has_html( $type ) {
130 $has_html = self::field_has_property( $type, 'has_html' );
131
132 // this hook is here for reverse compatibility since 3.0
133 return apply_filters( 'frm_show_custom_html', $has_html, $type );
134 }
135
136 /**
137 * @since 3.0
138 *
139 * @param string $type
140 * @param string $property
141 *
142 * @return mixed
143 */
144 public static function field_has_property( $type, $property ) {
145 $field = self::get_field_type( $type );
146
147 return $field->{$property};
148 }
149 }
150