field-group-field.php 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. <?php
  2. //phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- included template file.
  3. // Define input name prefix using unique identifier.
  4. $input_prefix = 'acf_fields[' . $field['ID'] . ']';
  5. $input_id = acf_idify( $input_prefix );
  6. // Update field props.
  7. $field['prefix'] = $input_prefix;
  8. // Elements.
  9. $div_attrs = array(
  10. 'class' => 'acf-field-object acf-field-object-' . acf_slugify( $field['type'] ),
  11. 'data-id' => $field['ID'],
  12. 'data-key' => $field['key'],
  13. 'data-type' => $field['type'],
  14. );
  15. // Add additional class if the field is an endpoint.
  16. if ( isset( $field['endpoint'] ) && $field['endpoint'] ) {
  17. $div_attrs['class'] .= ' acf-field-is-endpoint';
  18. }
  19. // Misc template vars.
  20. $field_label = acf_get_field_label( $field, 'admin' );
  21. $field_type_label = acf_get_field_type_label( $field['type'] );
  22. if ( ! isset( $num_field_groups ) ) {
  23. $num_field_groups = 0;
  24. }
  25. ?>
  26. <div <?php echo acf_esc_attr( $div_attrs ); ?>>
  27. <div class="meta">
  28. <?php
  29. $meta_inputs = array(
  30. 'ID' => $field['ID'],
  31. 'key' => $field['key'],
  32. 'parent' => $field['parent'],
  33. 'menu_order' => $i,
  34. 'save' => '',
  35. );
  36. foreach ( $meta_inputs as $k => $v ) :
  37. acf_hidden_input(
  38. array(
  39. 'name' => $input_prefix . '[' . $k . ']',
  40. 'value' => $v,
  41. 'id' => $input_id . '-' . $k,
  42. )
  43. );
  44. endforeach;
  45. ?>
  46. </div>
  47. <div class="handle">
  48. <ul class="acf-hl acf-tbody">
  49. <li class="li-field-order">
  50. <span class="acf-icon acf-sortable-handle" title="<?php _e( 'Drag to reorder', 'acf' ); ?>"><?php echo ( $i + 1 ); ?></span>
  51. </li>
  52. <li class="li-field-label">
  53. <strong>
  54. <a class="edit-field" title="<?php _e( 'Edit field', 'acf' ); ?>" href="#"><?php echo acf_esc_html( $field_label ); ?></a>
  55. </strong>
  56. <div class="row-options">
  57. <a class="edit-field" title="<?php _e( 'Edit field', 'acf' ); ?>" href="#"><?php _e( 'Edit', 'acf' ); ?></a>
  58. <a class="duplicate-field" title="<?php _e( 'Duplicate field', 'acf' ); ?>" href="#"><?php _e( 'Duplicate', 'acf' ); ?></a>
  59. <?php if ( $num_field_groups > 1 ) : ?>
  60. <a class="move-field" title="<?php _e( 'Move field to another group', 'acf' ); ?>" href="#"><?php _e( 'Move', 'acf' ); ?></a>
  61. <?php endif; ?>
  62. <a class="delete-field" title="<?php _e( 'Delete field', 'acf' ); ?>" href="#"><?php _e( 'Delete', 'acf' ); ?></a>
  63. </div>
  64. </li>
  65. <li class="li-field-name"><span class="copyable"><?php echo esc_html( $field['name'] ); ?></span></li>
  66. <li class="li-field-key"><span class="copyable"><?php echo esc_html( $field['key'] ); ?></span></li>
  67. <li class="li-field-type">
  68. <i class="field-type-icon field-type-icon-<?php echo acf_slugify( $field['type'] ); ?>"></i>
  69. <span class="field-type-label">
  70. <?php echo acf_esc_html( $field_type_label ); ?>
  71. </span>
  72. </li>
  73. </ul>
  74. </div>
  75. <div class="settings">
  76. <div class="acf-field-editor">
  77. <div class="acf-field-settings acf-fields">
  78. <?php
  79. acf_render_field_wrap(
  80. array(
  81. 'type' => 'tab',
  82. 'label' => __( 'General', 'acf' ),
  83. 'key' => 'acf_field_settings_tabs',
  84. 'settings-type' => 'general',
  85. )
  86. );
  87. ?>
  88. <div class="acf-field-settings-main acf-field-settings-main-general">
  89. <?php
  90. // type
  91. acf_render_field_setting(
  92. $field,
  93. array(
  94. 'label' => __( 'Field Type', 'acf' ),
  95. 'instructions' => '',
  96. 'type' => 'select',
  97. 'name' => 'type',
  98. 'choices' => acf_get_grouped_field_types(),
  99. 'class' => 'field-type',
  100. ),
  101. true
  102. );
  103. // label
  104. acf_render_field_setting(
  105. $field,
  106. array(
  107. 'label' => __( 'Field Label', 'acf' ),
  108. 'instructions' => __( 'This is the name which will appear on the EDIT page', 'acf' ),
  109. 'name' => 'label',
  110. 'type' => 'text',
  111. 'class' => 'field-label',
  112. ),
  113. true
  114. );
  115. // name
  116. acf_render_field_setting(
  117. $field,
  118. array(
  119. 'label' => __( 'Field Name', 'acf' ),
  120. 'instructions' => __( 'Single word, no spaces. Underscores and dashes allowed', 'acf' ),
  121. 'name' => 'name',
  122. 'type' => 'text',
  123. 'class' => 'field-name',
  124. ),
  125. true
  126. );
  127. // 3rd party settings
  128. do_action( 'acf/render_field_settings', $field );
  129. // type specific settings
  130. ?>
  131. <div class="acf-field-type-settings" data-parent-tab="general">
  132. <?php
  133. do_action( "acf/render_field_settings/type={$field['type']}", $field );
  134. do_action( "acf/render_field_general_settings/type={$field['type']}", $field );
  135. ?>
  136. </div>
  137. </div><!-- /.acf-field-settings-main-general -->
  138. <?php
  139. acf_render_field_wrap(
  140. array(
  141. 'type' => 'tab',
  142. 'label' => __( 'Validation', 'acf' ),
  143. 'key' => 'acf_field_settings_tabs',
  144. 'settings-type' => 'validation',
  145. )
  146. );
  147. ?>
  148. <div class="acf-field-settings-main acf-field-settings-main-validation">
  149. <?php
  150. // required
  151. acf_render_field_setting(
  152. $field,
  153. array(
  154. 'label' => __( 'Required', 'acf' ),
  155. 'instructions' => '',
  156. 'type' => 'true_false',
  157. 'name' => 'required',
  158. 'ui' => 1,
  159. 'class' => 'field-required',
  160. ),
  161. true
  162. );
  163. ?>
  164. <div class="acf-field-type-settings" data-parent-tab="validation">
  165. <?php do_action( "acf/render_field_validation_settings/type={$field['type']}", $field ); ?>
  166. </div>
  167. </div><!-- /.acf-field-settings-main-validation -->
  168. <?php
  169. acf_render_field_wrap(
  170. array(
  171. 'type' => 'tab',
  172. 'label' => __( 'Presentation', 'acf' ),
  173. 'key' => 'acf_field_settings_tabs',
  174. 'settings-type' => 'presentation',
  175. )
  176. );
  177. ?>
  178. <div class="acf-field-settings-main acf-field-settings-main-presentation">
  179. <?php
  180. acf_render_field_setting(
  181. $field,
  182. array(
  183. 'label' => __( 'Instructions', 'acf' ),
  184. 'instructions' => __( 'Instructions for authors. Shown when submitting data', 'acf' ),
  185. 'type' => 'textarea',
  186. 'name' => 'instructions',
  187. 'rows' => 5,
  188. ),
  189. true
  190. );
  191. acf_render_field_wrap(
  192. array(
  193. 'label' => '',
  194. 'instructions' => '',
  195. 'type' => 'text',
  196. 'name' => 'class',
  197. 'prefix' => $field['prefix'] . '[wrapper]',
  198. 'value' => $field['wrapper']['class'],
  199. 'prepend' => __( 'class', 'acf' ),
  200. 'wrapper' => array(
  201. 'data-append' => 'wrapper',
  202. ),
  203. ),
  204. 'div'
  205. );
  206. acf_render_field_wrap(
  207. array(
  208. 'label' => '',
  209. 'instructions' => '',
  210. 'type' => 'text',
  211. 'name' => 'id',
  212. 'prefix' => $field['prefix'] . '[wrapper]',
  213. 'value' => $field['wrapper']['id'],
  214. 'prepend' => __( 'id', 'acf' ),
  215. 'wrapper' => array(
  216. 'data-append' => 'wrapper',
  217. ),
  218. ),
  219. 'div'
  220. );
  221. ?>
  222. <div class="acf-field-type-settings" data-parent-tab="presentation">
  223. <?php do_action( "acf/render_field_presentation_settings/type={$field['type']}", $field ); ?>
  224. </div>
  225. <?php
  226. acf_render_field_wrap(
  227. array(
  228. 'label' => __( 'Wrapper Attributes', 'acf' ),
  229. 'instructions' => '',
  230. 'type' => 'number',
  231. 'name' => 'width',
  232. 'prefix' => $field['prefix'] . '[wrapper]',
  233. 'value' => $field['wrapper']['width'],
  234. 'prepend' => __( 'width', 'acf' ),
  235. 'append' => '%',
  236. 'wrapper' => array(
  237. 'data-name' => 'wrapper',
  238. 'class' => 'acf-field-setting-wrapper',
  239. ),
  240. ),
  241. 'div'
  242. );
  243. ?>
  244. </div><!-- /.acf-field-settings-main-presentation -->
  245. <?php
  246. $conditional_logic_class = $conditional_logic_text = '';
  247. if ( isset( $field['conditional_logic'] ) && is_array( $field['conditional_logic'] ) && count( $field['conditional_logic'] ) > 0 ) {
  248. $conditional_logic_class = ' is-enabled';
  249. $conditional_logic_text = __( 'Active', 'acf' );
  250. }
  251. acf_render_field_wrap(
  252. array(
  253. 'type' => 'tab',
  254. 'label' => __( 'Conditional Logic', 'acf' ) . '<i class="conditional-logic-badge' . $conditional_logic_class . '">' . $conditional_logic_text . '</i>',
  255. 'key' => 'acf_field_settings_tabs',
  256. 'settings-type' => 'conditional_logic',
  257. )
  258. );
  259. ?>
  260. <div class="acf-field-settings-main acf-field-settings-main-conditional-logic">
  261. <?php acf_get_view( 'field-group-field-conditional-logic', array( 'field' => $field ) ); ?>
  262. <div class="acf-field-type-settings" data-parent-tab="conditional_logic">
  263. <?php do_action( "acf/render_field_conditional_logic_settings/type={$field['type']}", $field ); ?>
  264. </div>
  265. </div><!-- /.acf-field-settings-main-conditional-logic -->
  266. <div class="acf-field-settings-footer">
  267. <a class="button close-field edit-field" title="<?php _e( 'Close Field', 'acf' ); ?>" href="#"><?php _e( 'Close Field', 'acf' ); ?></a>
  268. </div>
  269. </div>
  270. </div>
  271. </div>
  272. </div>