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

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