@@ -224,7 +224,82 @@ public function get_cloned_fields( $field ) {
224
224
return $ fields ;
225
225
}
226
226
227
+ /**
228
+ * This function is run when cloning a clone field
229
+ * Important to run the acf_clone_field function on sub fields to pass on settings such as 'parent_layout'
230
+ *
231
+ * @type function
232
+ * @date 28/06/2016
233
+ * @since 5.3.8
234
+ *
235
+ * @param array $field The field array.
236
+ * @param array $clone_field The clone field array.
237
+ * @return array $field
238
+ */
239
+ public function acf_clone_field ( $ field , $ clone_field ) {
240
+
241
+ // bail early if this field is being cloned by some other kind of field (future proof)
242
+ if ( 'clone ' !== $ clone_field ['type ' ] ) {
243
+ return $ field ;
244
+ }
245
+
246
+ // backup (used later)
247
+ // - backup only once (cloned clone fields can cause issues)
248
+ if ( ! isset ( $ field ['__key ' ] ) ) {
249
+ $ field ['__key ' ] = $ field ['key ' ];
250
+ $ field ['__name ' ] = $ field ['_name ' ];
251
+ $ field ['__label ' ] = $ field ['label ' ];
252
+ }
253
+
254
+ // seamless
255
+ if ( 'seamless ' === $ clone_field ['display ' ] ) {
256
+
257
+ // modify key
258
+ // - this will allow sub clone fields to correctly load values for the same cloned field
259
+ // - the original key will later be restored by acf/prepare_field allowing conditional logic JS to work
260
+ $ field ['key ' ] = $ clone_field ['key ' ] . '_ ' . $ field ['key ' ];
261
+
262
+ // modify prefix allowing clone field to save sub fields
263
+ // - only used for parent seamless fields. Block or sub field's prefix will be overriden which also works
264
+ $ field ['prefix ' ] = $ clone_field ['prefix ' ] . '[ ' . $ clone_field ['key ' ] . '] ' ;
265
+
266
+ // modify parent
267
+ $ field ['parent ' ] = $ clone_field ['parent ' ];
227
268
269
+ // label_format
270
+ if ( $ clone_field ['prefix_label ' ] ) {
271
+ $ field ['label ' ] = $ clone_field ['label ' ] . ' ' . $ field ['label ' ];
272
+ }
273
+ }
274
+
275
+ // prefix_name
276
+ if ( $ clone_field ['prefix_name ' ] ) {
277
+
278
+ // modify the field name
279
+ // - this will allow field to load / save correctly
280
+ $ field ['name ' ] = $ clone_field ['name ' ] . '_ ' . $ field ['_name ' ];
281
+
282
+ // modify the field _name (orig name)
283
+ // - this will allow fields to correctly understand the modified field
284
+ if ( 'seamless ' === $ clone_field ['display ' ] ) {
285
+ $ field ['_name ' ] = $ clone_field ['_name ' ] . '_ ' . $ field ['_name ' ];
286
+ }
287
+ }
288
+
289
+ // required
290
+ if ( $ clone_field ['required ' ] ) {
291
+ $ field ['required ' ] = 1 ;
292
+ }
293
+
294
+ // type specific
295
+ // note: seamless clone fields will not be triggered
296
+ if ( 'clone ' === $ field ['type ' ] ) {
297
+ $ field = $ this ->acf_clone_clone_field ( $ field , $ clone_field );
298
+ }
299
+
300
+ // return
301
+ return $ field ;
302
+ }
228
303
/**
229
304
* This function is run when cloning a clone field
230
305
* Important to run the acf_clone_field function on sub fields to pass on settings such as 'parent_layout'
0 commit comments