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

142 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 * @return FrmFieldType
40 */
41 public static function get_field_factory( $field ) {
42 if ( is_object( $field ) ) {
43 $field_info = self::get_field_object( $field );
44 } elseif ( isset( $field['id'] ) && $field['id'] ) {
45 $field_info = self::get_field_object( $field['id'] );
46 } else {
47 $field_info = self::get_field_type( $field['type'], $field );
48 }
49
50 return $field_info;
51 }
52
53 /**
54 * @param int|object|string $field
55 *
56 * @return FrmFieldType
57 */
58 public static function get_field_object( $field ) {
59 if ( ! is_object( $field ) ) {
60 $field = FrmField::getOne( $field );
61 }
62
63 return self::get_field_type( $field->type, $field );
64 }
65
66 /**
67 * @since 3.0
68 *
69 * @param string $field_type
70 * @param array|int|object $field
71 *
72 * @return FrmFieldType
73 */
74 public static function get_field_type( $field_type, $field = 0 ) {
75 $class = self::get_field_type_class( $field_type );
76 if ( empty( $class ) ) {
77 $field = new FrmFieldDefault( $field, $field_type );
78 } else {
79 $field = new $class( $field, $field_type );
80 }
81
82 return $field;
83 }
84
85 /**
86 * @since 3.0
87 *
88 * @param string $field_type
89 *
90 * @return string
91 */
92 private static function get_field_type_class( $field_type ) {
93 $type_classes = array(
94 'text' => 'FrmFieldText',
95 'textarea' => 'FrmFieldTextarea',
96 'select' => 'FrmFieldSelect',
97 'radio' => 'FrmFieldRadio',
98 'checkbox' => 'FrmFieldCheckbox',
99 'number' => 'FrmFieldNumber',
100 'phone' => 'FrmFieldPhone',
101 'url' => 'FrmFieldUrl',
102 'website' => 'FrmFieldUrl',
103 'email' => 'FrmFieldEmail',
104 'user_id' => 'FrmFieldUserID',
105 'html' => 'FrmFieldHTML',
106 'hidden' => 'FrmFieldHidden',
107 'captcha' => 'FrmFieldCaptcha',
108 'name' => 'FrmFieldName',
109 'credit_card' => 'FrmFieldCreditCard',
110 // Submit button field.
111 FrmSubmitHelper::FIELD_TYPE => 'FrmFieldSubmit',
112 FrmFieldGdprHelper::FIELD_TYPE => FrmFieldGdprHelper::get_gdpr_field_class( $field_type ),
113 );
114
115 $class = isset( $type_classes[ $field_type ] ) ? $type_classes[ $field_type ] : '';
116
117 return apply_filters( 'frm_get_field_type_class', $class, $field_type );
118 }
119
120 /**
121 * @since 3.0
122 */
123 public static function field_has_html( $type ) {
124 $has_html = self::field_has_property( $type, 'has_html' );
125
126 // this hook is here for reverse compatibility since 3.0
127 return apply_filters( 'frm_show_custom_html', $has_html, $type );
128 }
129
130 /**
131 * @since 3.0
132 *
133 * @param string $type
134 * @param string $property
135 */
136 public static function field_has_property( $type, $property ) {
137 $field = self::get_field_type( $type );
138
139 return $field->{$property};
140 }
141 }
142