Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 30 additions & 11 deletions src/Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
*/
Expand Down Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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',
Expand Down