Skip to content
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

[Unreleased]

## [1.42.0]

### Added
- Support for registering example data for ACF Blocks.

## [1.41.8]

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Plugin Name: ACF Codifier
Plugin URI: https://github.com/devgeniem/acf-codifier
Description: A helper class to make defining ACF field groups and fields easier in the code.
Version: 1.41.8
Version: 1.42.0
Author: Miika Arponen / Geniem Oy
Author URI: https://geniem.fi
License: GPL-3.0
Expand Down
35 changes: 35 additions & 0 deletions src/Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,16 @@ class Block implements GroupableInterface {
*/
protected $parent = null;

/**
* An array of example data for the block.
*
* @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-registration/#example-optional
* @see https://www.advancedcustomfields.com/resources/acf_register_block_type/
*
* @var array
*/
protected $example = [];

/**
* The renderer for this block.
*
Expand Down Expand Up @@ -470,6 +480,18 @@ public function set_parent( ?array $parent ) : self {
return $this;
}
Comment thread
Copilot marked this conversation as resolved.

/**
* Setter for the block example data.
*
* @param array $example Array of example data.
* @return self
*/
public function set_example( array $example ) : self {
$this->example = $example;

return $this;
}

/**
* Getter for the parent of the block.
*
Expand All @@ -479,6 +501,15 @@ public function get_parent() : ?array {
return $this->parent;
}

/*
* Getter for the example data of the block.
*
* @return array
*/
public function get_example() : array {
return $this->example;
}

/**
* Add a data filtering function for the block
*
Expand Down Expand Up @@ -588,6 +619,10 @@ protected function register_block() {
$args['post_types'] = $post_types;
}

if ( ! empty( $this->get_example() ) ) {
$args['example'] = $this->get_example();
}

// Register the ACF Block.
return \acf_register_block( $args );
}
Expand Down
Loading