diff --git a/src/Block.php b/src/Block.php index c82f58b..ea248b1 100644 --- a/src/Block.php +++ b/src/Block.php @@ -280,9 +280,9 @@ abstract class Block extends Composer implements BlockContract /** * The internal ACF block version. * - * @var int + * @var int|null */ - public $blockVersion = 2; + public $blockVersion; /** * Validate block fields as per the field group configuration. @@ -291,6 +291,13 @@ abstract class Block extends Composer implements BlockContract */ public $validate = true; + /** + * Enable inline editing for block fields (ACF Pro 6.7+). + * + * @var bool|null + */ + public $autoInlineEditing = null; + /** * The block attributes. */ @@ -521,6 +528,14 @@ public function getApiVersion(): int return $this->apiVersion ?? 2; } + /** + * Retrieve the block version. + */ + public function getBlockVersion(): int + { + return $this->blockVersion ?? 2; + } + /** * Retrieve the block text domain. */ @@ -664,7 +679,7 @@ public function settings(): Collection 'styles' => $this->getStyles(), 'supports' => $this->getSupports(), 'textdomain' => $this->getTextDomain(), - 'acf_block_version' => $this->blockVersion, + 'acf_block_version' => $this->getBlockVersion(), 'api_version' => $this->getApiVersion(), 'validate' => $this->validate, 'use_post_meta' => $this->usePostMeta, @@ -717,17 +732,21 @@ public function settings(): Collection */ public function toJson(): string { + $acf = Collection::make([ + 'blockVersion' => $this->getBlockVersion(), + 'mode' => $this->mode, + 'postTypes' => $this->post_types, + 'renderTemplate' => $this::class, + 'usePostMeta' => $this->usePostMeta, + 'validate' => $this->validate, + ])->when($this->getBlockVersion() >= 3, function (Collection $acf) { + return $acf->put('autoInlineEditing', $this->autoInlineEditing ?? false); + }); + $settings = $this->settings() ->put('name', $this->namespace) ->put('apiVersion', $this->getApiVersion()) - ->put('acf', [ - 'blockVersion' => $this->blockVersion, - 'mode' => $this->mode, - 'postTypes' => $this->post_types, - 'renderTemplate' => $this::class, - 'usePostMeta' => $this->usePostMeta, - 'validate' => $this->validate, - ]) + ->put('acf', $acf) ->forget([ 'api_version', 'acf_block_version',