diff --git a/CHANGELOG.md b/CHANGELOG.md index e83a174..112a074 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/plugin.php b/plugin.php index 960c671..80a5acd 100644 --- a/plugin.php +++ b/plugin.php @@ -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 diff --git a/src/Block.php b/src/Block.php index 6ffbc1b..536531d 100644 --- a/src/Block.php +++ b/src/Block.php @@ -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. * @@ -470,6 +480,18 @@ public function set_parent( ?array $parent ) : self { return $this; } + /** + * 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. * @@ -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 * @@ -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 ); }