/core/views/meta_box_fields.php

  1. <?php 
  2.  
  3. /** 
  4. * Meta box - fields 
  5. * 
  6. * This template file is used when editing a field group and creates the interface for editing fields. 
  7. * 
  8. * @type template 
  9. * @date 26/01/13 
  10. */ 
  11.  
  12.  
  13. // global 
  14. global $post, $field_types; 
  15.  
  16.  
  17. // get fields 
  18. $fields = apply_filters('acf/field_group/get_fields', array(), $post->ID); 
  19.  
  20.  
  21. // add clone 
  22. $fields[] = apply_filters('acf/load_field_defaults', array( 
  23. 'key' => 'field_clone',  
  24. 'label' => __("New Field", 'acf'),  
  25. 'name' => 'new_field',  
  26. 'type' => 'text',  
  27. )); 
  28.  
  29.  
  30. // get name of all fields for use in field type drop down 
  31. $field_types = apply_filters('acf/registered_fields', array()); 
  32.  
  33.  
  34. // helper function 
  35. function field_type_exists( $name ) 
  36. global $field_types; 
  37.  
  38. foreach( $field_types as $category ) 
  39. if( isset( $category[ $name ] ) ) 
  40. return $category[ $name ]; 
  41.  
  42. return false; 
  43.  
  44.  
  45. // conditional logic dummy data 
  46. $conditional_logic_rule = array( 
  47. 'field' => '',  
  48. 'operator' => '==',  
  49. 'value' => '' 
  50. ); 
  51.  
  52. $error_field_type = '<b>' . __('Error', 'acf') . '</b> ' . __('Field type does not exist', 'acf'); 
  53.  
  54. ?> 
  55.  
  56. <!-- Hidden Fields --> 
  57. <div style="display:none;"> 
  58. <input type="hidden" name="acf_nonce" value="<?php echo wp_create_nonce( 'field_group' ); ?>" /> 
  59. </div> 
  60. <!-- / Hidden Fields --> 
  61.  
  62.  
  63. <!-- Fields Header --> 
  64. <div class="fields_header"> 
  65. <table class="acf widefat"> 
  66. <thead> 
  67. <tr> 
  68. <th class="field_order"><?php _e('Field Order', 'acf'); ?></th> 
  69. <th class="field_label"><?php _e('Field Label', 'acf'); ?></th> 
  70. <th class="field_name"><?php _e('Field Name', 'acf'); ?></th> 
  71. <th class="field_type"><?php _e('Field Type', 'acf'); ?></th> 
  72. <th class="field_key"><?php _e('Field Key', 'acf'); ?></th> 
  73. </tr> 
  74. </thead> 
  75. </table> 
  76. </div> 
  77. <!-- / Fields Header --> 
  78.  
  79.  
  80. <div class="fields"> 
  81.  
  82. <!-- No Fields Message --> 
  83. <div class="no_fields_message" <?php if(count($fields) > 1) { echo 'style="display:none;"'; } ?>> 
  84. <?php _e("No fields. Click the <strong>+ Add Field</strong> button to create your first field.", 'acf'); ?> 
  85. </div> 
  86. <!-- / No Fields Message --> 
  87.  
  88. <?php foreach($fields as $field):  
  89. $fake_name = $field['key']; 
  90. ?> 
  91. <div class="field field_type-<?php echo $field['type']; ?> field_key-<?php echo $field['key']; ?>" data-type="<?php echo $field['type']; ?>" data-id="<?php echo $field['key']; ?>"> 
  92. <input type="hidden" class="input-field_key" name="fields[<?php echo $field['key']; ?>][key]" value="<?php echo $field['key']; ?>" /> 
  93. <div class="field_meta"> 
  94. <table class="acf widefat"> 
  95. <tr> 
  96. <td class="field_order"><span class="circle"><?php echo (int)$field['order_no'] + 1; ?></span></td> 
  97. <td class="field_label"> 
  98. <strong> 
  99. <a class="acf_edit_field row-title" title="<?php _e("Edit this Field", 'acf'); ?>" href="javascript:;"><?php echo $field['label']; ?></a> 
  100. </strong> 
  101. <div class="row_options"> 
  102. <span><a class="acf_edit_field" title="<?php _e("Edit this Field", 'acf'); ?>" href="javascript:;"><?php _e("Edit", 'acf'); ?></a> | </span> 
  103. <span><a class="acf_duplicate_field" title="<?php _e("Duplicate this Field", 'acf'); ?>" href="javascript:;"><?php _e("Duplicate", 'acf'); ?></a> | </span> 
  104. <span><a class="acf_delete_field" title="<?php _e("Delete this Field", 'acf'); ?>" href="javascript:;"><?php _e("Delete", 'acf'); ?></a></span> 
  105. </div> 
  106. </td> 
  107. <td class="field_name"><?php echo $field['name']; ?></td> 
  108. <td class="field_type"><?php $l = field_type_exists( $field['type'] ); if( $l ) { echo $l; }else{ echo $error_field_type; } ?></td> 
  109. <td class="field_key"><?php echo $field['key']; ?></td> 
  110. </tr> 
  111. </table> 
  112. </div> 
  113. <div class="field_form_mask"> 
  114. <div class="field_form"> 
  115.  
  116. <table class="acf_input widefat acf_field_form_table"> 
  117. <tbody> 
  118. <tr class="field_label"> 
  119. <td class="label"> 
  120. <label><?php _e("Field Label", 'acf'); ?><span class="required">*</span></label> 
  121. <p class="description"><?php _e("This is the name which will appear on the EDIT page", 'acf'); ?></p> 
  122. </td> 
  123. <td> 
  124. <?php  
  125. do_action('acf/create_field', array( 
  126. 'type' => 'text',  
  127. 'name' => 'fields[' .$fake_name . '][label]',  
  128. 'value' => $field['label'],  
  129. 'class' => 'label',  
  130. )); 
  131. ?> 
  132. </td> 
  133. </tr> 
  134. <tr class="field_name"> 
  135. <td class="label"> 
  136. <label><?php _e("Field Name", 'acf'); ?><span class="required">*</span></label> 
  137. <p class="description"><?php _e("Single word, no spaces. Underscores and dashes allowed", 'acf'); ?></p> 
  138. </td> 
  139. <td> 
  140. <?php  
  141. do_action('acf/create_field', array( 
  142. 'type' => 'text',  
  143. 'name' => 'fields[' .$fake_name . '][name]',  
  144. 'value' => $field['name'],  
  145. 'class' => 'name',  
  146. )); 
  147. ?> 
  148. </td> 
  149. </tr> 
  150. <tr class="field_type"> 
  151. <td class="label"> 
  152. <label><?php _e("Field Type", 'acf'); ?><span class="required">*</span></label> 
  153. </td> 
  154. <td> 
  155. <?php 
  156. do_action('acf/create_field', array( 
  157. 'type' => 'select',  
  158. 'name' => 'fields[' .$fake_name . '][type]',  
  159. 'value' => $field['type'],  
  160. 'choices' => $field_types,  
  161. )); 
  162. ?> 
  163. </td> 
  164. </tr> 
  165. <tr class="field_instructions"> 
  166. <td class="label"><label><?php _e("Field Instructions", 'acf'); ?></label> 
  167. <p class="description"><?php _e("Instructions for authors. Shown when submitting data", 'acf'); ?></p></td> 
  168. <td> 
  169. <?php  
  170. do_action('acf/create_field', array( 
  171. 'type' => 'textarea',  
  172. 'name' => 'fields[' .$fake_name . '][instructions]',  
  173. 'value' => $field['instructions'],  
  174. 'rows' => 6 
  175. )); 
  176. ?> 
  177. </td> 
  178. </tr> 
  179. <tr class="required"> 
  180. <td class="label"><label><?php _e("Required?", 'acf'); ?></label></td> 
  181. <td> 
  182. <?php  
  183. do_action('acf/create_field', array( 
  184. 'type' => 'radio',  
  185. 'name' => 'fields[' .$fake_name . '][required]',  
  186. 'value' => $field['required'],  
  187. 'choices' => array( 
  188. 1 => __("Yes", 'acf'),  
  189. 0 => __("No", 'acf'),  
  190. ),  
  191. 'layout' => 'horizontal',  
  192. )); 
  193. ?> 
  194. </td> 
  195. </tr> 
  196. <?php  
  197.  
  198. $field['name'] = $fake_name; 
  199. do_action('acf/create_field_options', $field ); 
  200.  
  201. ?> 
  202. <tr class="conditional-logic" data-field_name="<?php echo $field['key']; ?>"> 
  203. <td class="label"><label><?php _e("Conditional Logic", 'acf'); ?></label></td> 
  204. <td> 
  205. <?php  
  206. do_action('acf/create_field', array( 
  207. 'type' => 'radio',  
  208. 'name' => 'fields['.$field['key'].'][conditional_logic][status]',  
  209. 'value' => $field['conditional_logic']['status'],  
  210. 'choices' => array( 
  211. 1 => __("Yes", 'acf'),  
  212. 0 => __("No", 'acf'),  
  213. ),  
  214. 'layout' => 'horizontal',  
  215. )); 
  216.  
  217.  
  218. // no rules? 
  219. if( ! $field['conditional_logic']['rules'] ) 
  220. $field['conditional_logic']['rules'] = array( 
  221. array() // this will get merged with $conditional_logic_rule 
  222. ); 
  223.  
  224. ?> 
  225. <div class="contional-logic-rules-wrapper" <?php if( ! $field['conditional_logic']['status'] ) echo 'style="display:none"'; ?>> 
  226. <table class="conditional-logic-rules widefat acf-rules <?php if( count($field['conditional_logic']['rules']) == 1) echo 'remove-disabled'; ?>"> 
  227. <tbody> 
  228. <?php foreach( $field['conditional_logic']['rules'] as $rule_i => $rule ):  
  229.  
  230. // validate 
  231. $rule = array_merge($conditional_logic_rule, $rule); 
  232.  
  233.  
  234. // fix PHP error in 3.5.4.1 
  235. if( strpos($rule['value'], 'Undefined index: value in') !== false ) 
  236. $rule['value'] = ''; 
  237.  
  238. ?> 
  239. <tr data-i="<?php echo $rule_i; ?>"> 
  240. <td> 
  241. <input class="conditional-logic-field" type="hidden" name="fields[<?php echo $field['key']; ?>][conditional_logic][rules][<?php echo $rule_i; ?>][field]" value="<?php echo $rule['field']; ?>" /> 
  242. </td> 
  243. <td width="25%"> 
  244. <?php  
  245. do_action('acf/create_field', array( 
  246. 'type' => 'select',  
  247. 'name' => 'fields['.$field['key'].'][conditional_logic][rules][' . $rule_i . '][operator]',  
  248. 'value' => $rule['operator'],  
  249. 'choices' => array( 
  250. '==' => __("is equal to", 'acf'),  
  251. '!=' => __("is not equal to", 'acf'),  
  252. ),  
  253. )); 
  254. ?> 
  255. </td> 
  256. <td><input class="conditional-logic-value" type="hidden" name="fields[<?php echo $field['key']; ?>][conditional_logic][rules][<?php echo $rule_i; ?>][value]" value="<?php echo $rule['value']; ?>" /></td> 
  257. <td class="buttons"> 
  258. <ul class="hl clearfix"> 
  259. <li><a class="acf-button-remove" href="javascript:;"></a></li> 
  260. <li><a class="acf-button-add" href="javascript:;"></a></li> 
  261. </ul> 
  262. </td> 
  263. </tr>  
  264. <?php endforeach; ?> 
  265. </tbody> 
  266. </table> 
  267.  
  268. <ul class="hl clearfix"> 
  269. <li style="padding:4px 4px 0 0;"><?php _e("Show this field when", 'acf'); ?></li> 
  270. <li><?php do_action('acf/create_field', array( 
  271. 'type' => 'select',  
  272. 'name' => 'fields['.$field['key'].'][conditional_logic][allorany]',  
  273. 'value' => $field['conditional_logic']['allorany'],  
  274. 'choices' => array( 
  275. 'all' => __("all", 'acf'),  
  276. 'any' => __("any", 'acf'),  
  277. ),  
  278. )); ?></li> 
  279. <li style="padding:4px 0 0 4px;"><?php _e("these rules are met", 'acf'); ?></li> 
  280. </ul> 
  281.  
  282. </div> 
  283.  
  284.  
  285.  
  286. </td> 
  287. </tr> 
  288. <tr class="field_save"> 
  289. <td class="label"></td> 
  290. <td> 
  291. <ul class="hl clearfix"> 
  292. <li> 
  293. <a class="acf_edit_field acf-button grey" title="<?php _e("Close Field", 'acf'); ?>" href="javascript:;"><?php _e("Close Field", 'acf'); ?></a> 
  294. </li> 
  295. </ul> 
  296. </td> 
  297. </tr> 
  298. </tbody> 
  299. </table> 
  300. </div> 
  301. </div>  
  302. </div> 
  303. <?php endforeach; ?> 
  304. </div> 
  305. <div class="table_footer"> 
  306. <div class="order_message"><?php _e('Drag and drop to reorder', 'acf'); ?></div> 
  307. <a href="javascript:;" id="add_field" class="acf-button"><?php _e('+ Add Field', 'acf'); ?></a> 
  308. </div> 
.