1
|
|
|
<?php |
|
|
|
|
2
|
|
|
/** |
3
|
|
|
* @package Pods\Components |
4
|
|
|
* @subpackage Builder |
5
|
|
|
*/ |
6
|
|
|
if ( !class_exists( 'LayoutModule' ) ) |
7
|
|
|
return; |
8
|
|
|
|
9
|
|
|
if ( !class_exists( 'PodsBuilderModuleForm' ) ) { |
10
|
|
|
class PodsBuilderModuleForm extends LayoutModule { |
11
|
|
|
|
12
|
|
|
var $_name = ''; |
|
|
|
|
13
|
|
|
var $_var = 'pods-builder-form'; |
|
|
|
|
14
|
|
|
var $_description = ''; |
|
|
|
|
15
|
|
|
var $_editor_width = 500; |
|
|
|
|
16
|
|
|
var $_can_remove_wrappers = true; |
|
|
|
|
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Register the Module |
20
|
|
|
*/ |
21
|
|
View Code Duplication |
public function __construct () { |
|
|
|
|
22
|
|
|
$this->_name = __( 'Pods - Form', 'pods' ); |
23
|
|
|
$this->_description = __( 'Display a form for creating and editing Pod items', 'pods' ); |
24
|
|
|
$this->module_path = dirname( __FILE__ ); |
25
|
|
|
|
26
|
|
|
$this->LayoutModule(); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Set default variables |
31
|
|
|
* |
32
|
|
|
* @param $defaults |
33
|
|
|
* |
34
|
|
|
* @return mixed |
35
|
|
|
*/ |
36
|
|
|
function _get_defaults ( $defaults ) { |
|
|
|
|
37
|
|
|
$new_defaults = array( |
38
|
|
|
'pod_type' => '', |
39
|
|
|
'slug' => '', |
40
|
|
|
'fields' => '', |
41
|
|
|
'label' => __( 'Submit', 'pods' ), |
42
|
|
|
'thank_you' => '', |
43
|
|
|
'sidebar' => 'none' |
44
|
|
|
); |
45
|
|
|
|
46
|
|
|
return ITUtility::merge_defaults( $new_defaults, $defaults ); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Output something before the table form |
51
|
|
|
* |
52
|
|
|
* @param object $form Form class |
53
|
|
|
* @param bool $results |
54
|
|
|
*/ |
55
|
|
|
function _before_table_edit ( $form, $results = true ) { |
|
|
|
|
56
|
|
|
?> |
57
|
|
|
<p><?php echo $this->_description; ?></p> |
58
|
|
|
<?php |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Output something at the start of the table form |
63
|
|
|
* |
64
|
|
|
* @param object $form Form class |
65
|
|
|
* @param bool $results |
66
|
|
|
*/ |
67
|
|
|
function _start_table_edit ( $form, $results = true ) { |
|
|
|
|
68
|
|
|
$api = pods_api(); |
69
|
|
|
$all_pods = $api->load_pods( array( 'names' => true ) ); |
70
|
|
|
|
71
|
|
|
$pod_types = array(); |
72
|
|
|
|
73
|
|
|
foreach ( $all_pods as $pod_name => $pod_label ) { |
|
|
|
|
74
|
|
|
$pod_types[ $pod_name ] = $pod_label . ' (' . $pod_name . ')'; |
75
|
|
|
} |
76
|
|
|
?> |
77
|
|
|
<tr> |
78
|
|
|
<td valign="top"> |
79
|
|
|
<label for="pod_type"><?php _e( 'Pod', 'pods' ); ?></label> |
80
|
|
|
</td> |
81
|
|
|
<td> |
82
|
|
|
<?php |
83
|
|
View Code Duplication |
if ( 0 < count( $all_pods ) ) |
84
|
|
|
$form->add_drop_down( 'pod_type', $pod_types ); |
85
|
|
|
else |
86
|
|
|
echo '<strong class="red">' . __( 'None Found', 'pods' ) . '</strong>'; |
87
|
|
|
?> |
88
|
|
|
</td> |
89
|
|
|
</tr> |
90
|
|
|
<tr> |
91
|
|
|
<td valign="top"> |
92
|
|
|
<label for="slug"><?php _e( 'Slug or ID', 'pods' ); ?></label> |
93
|
|
|
</td> |
94
|
|
|
<td> |
95
|
|
|
<?php $form->add_text_box( 'slug' ); ?> |
96
|
|
|
</td> |
97
|
|
|
</tr> |
98
|
|
|
<tr> |
99
|
|
|
<td valign="top"> |
100
|
|
|
<label for="fields"><?php _e( 'Fields (comma-separated)', 'pods' ); ?></label> |
101
|
|
|
</td> |
102
|
|
|
<td> |
103
|
|
|
<?php $form->add_text_box( 'fields' ); ?> |
104
|
|
|
</td> |
105
|
|
|
</tr> |
106
|
|
|
<tr> |
107
|
|
|
<td valign="top"> |
108
|
|
|
<label for="label"><?php _e( 'Submit Label', 'pods' ); ?></label> |
109
|
|
|
</td> |
110
|
|
|
<td> |
111
|
|
|
<?php $form->add_text_box( 'label' ); ?> |
112
|
|
|
</td> |
113
|
|
|
</tr> |
114
|
|
|
<tr> |
115
|
|
|
<td valign="top"> |
116
|
|
|
<label for="thank_you"><?php _e( 'Thank You URL upon submission', 'pods' ); ?></label> |
117
|
|
|
</td> |
118
|
|
|
<td> |
119
|
|
|
<?php $form->add_text_box( 'thank_you' ); ?> |
120
|
|
|
</td> |
121
|
|
|
</tr> |
122
|
|
|
<?php |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* Module Output |
127
|
|
|
*/ |
128
|
|
|
function _render ( $fields ) { |
|
|
|
|
129
|
|
|
$args = array( |
130
|
|
|
'name' => trim( pods_var_raw( 'pod_type', $fields[ 'data' ], '' ) ), |
131
|
|
|
'slug' => trim( pods_var_raw( 'slug', $fields[ 'data' ], '' ) ), |
132
|
|
|
'fields' => trim( pods_var_raw( 'fields', $fields[ 'data' ], '' ) ), |
133
|
|
|
'label' => trim( pods_var_raw( 'label', $fields[ 'data' ], __( 'Submit', 'pods' ), null, true ) ), |
134
|
|
|
'thank_you' => trim( pods_var_raw( 'thank_you', $fields[ 'data' ], '' ) ), |
135
|
|
|
'form' => 1 |
136
|
|
|
); |
137
|
|
|
|
138
|
|
|
if ( 0 < strlen( $args[ 'name' ] ) ) |
139
|
|
|
echo pods_shortcode( $args, ( isset( $content ) ? $content : null ) ); |
|
|
|
|
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
} |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
new PodsBuilderModuleForm(); |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.