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

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