@@ -271,18 +271,11 @@ abstract class Block extends Composer implements BlockContract
271
271
public $ usePostMeta = false ;
272
272
273
273
/**
274
- * The ACF block API version.
274
+ * The block API version.
275
275
*
276
- * @var int
276
+ * @var int|null
277
277
*/
278
- public $ blockVersion = 2 ;
279
-
280
- /**
281
- * The ACF block API version.
282
- *
283
- * @var int
284
- */
285
- public $ apiVersion = 2 ;
278
+ public $ apiVersion = null ;
286
279
287
280
/**
288
281
* Validate block fields as per the field group configuration.
@@ -304,12 +297,18 @@ public function attributes(): array
304
297
*/
305
298
public function mergeAttributes (): void
306
299
{
307
- if (! $ attributes = $ this ->attributes ()) {
308
- return ;
300
+ foreach ($ this ->attributes () as $ key => $ value ) {
301
+ if (! property_exists ($ this , $ key )) {
302
+ continue ;
303
+ }
304
+
305
+ $ this ->{$ key } = $ value ;
309
306
}
310
307
311
- foreach ($ attributes as $ key => $ value ) {
312
- if (! property_exists ($ this , $ key )) {
308
+ $ defaults = config ('acf.blocks ' , []);
309
+
310
+ foreach ($ defaults as $ key => $ value ) {
311
+ if (! property_exists ($ this , $ key ) || filled ($ this ->{$ key })) {
313
312
continue ;
314
313
}
315
314
@@ -495,6 +494,14 @@ public function getClasses(): string
495
494
);
496
495
}
497
496
497
+ /**
498
+ * Retrieve the block API version.
499
+ */
500
+ public function getApiVersion (): int
501
+ {
502
+ return $ this ->apiVersion ?? 2 ;
503
+ }
504
+
498
505
/**
499
506
* Retrieve the block text domain.
500
507
*/
@@ -638,8 +645,8 @@ public function settings(): Collection
638
645
'styles ' => $ this ->getStyles (),
639
646
'supports ' => $ this ->getSupports (),
640
647
'textdomain ' => $ this ->getTextDomain (),
641
- 'acf_block_version ' => $ this ->blockVersion ,
642
- 'api_version ' => $ this ->apiVersion ,
648
+ 'acf_block_version ' => $ this ->getApiVersion () ,
649
+ 'apiVersion ' => $ this ->getApiVersion () ,
643
650
'validate ' => $ this ->validate ,
644
651
'use_post_meta ' => $ this ->usePostMeta ,
645
652
'render_callback ' => function (
@@ -694,7 +701,7 @@ public function toJson(): string
694
701
$ settings = $ this ->settings ()
695
702
->put ('name ' , $ this ->namespace )
696
703
->put ('acf ' , [
697
- 'blockVersion ' => $ this ->blockVersion ,
704
+ 'blockVersion ' => $ this ->getApiVersion () ,
698
705
'mode ' => $ this ->mode ,
699
706
'postTypes ' => $ this ->post_types ,
700
707
'renderTemplate ' => $ this ::class,
0 commit comments