Skip to content

Commit

Permalink
πŸ§‘β€πŸ’» Add blockVersion & validate props for blocks (#300)
Browse files Browse the repository at this point in the history
  • Loading branch information
ouun authored Jan 7, 2025
1 parent 6c22d9f commit f4a88d7
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,20 @@ abstract class Block extends Composer implements BlockContract
*/
public $usePostMeta = false;

/**
* The ACF block API version.
*
* @var int
*/
public $blockVersion = 2;

/**
* Validate block fields as per the field group configuration.
*
* @var bool
*/
public $validate = true;

/**
* The block attributes.
*/
Expand Down Expand Up @@ -536,9 +550,9 @@ public function settings(): Collection
'supports' => $this->supports,
'enqueue_assets' => fn ($block) => method_exists($this, 'assets') ? $this->assets($block) : null,
'textdomain' => $this->getTextDomain(),
'acf_block_version' => 2,
'acf_block_version' => $this->blockVersion,
'api_version' => 2,
'validate' => true,
'validate' => $this->validate,
'use_post_meta' => $this->usePostMeta,
'render_callback' => function (
$block,
Expand Down Expand Up @@ -596,11 +610,14 @@ public function toJson(): string
'post_types',
'render_callback',
'use_post_meta',
'validate',
])->put('acf', [
'blockVersion' => $this->blockVersion,
'mode' => $this->mode,
'postTypes' => $this->post_types,
'renderTemplate' => $this::class,
'usePostMeta' => $this->usePostMeta,
'validate' => $this->validate,
])->put('name', $this->namespace);

return $settings->filter()->toJson(JSON_PRETTY_PRINT);
Expand Down

0 comments on commit f4a88d7

Please sign in to comment.