diff --git a/CHANGELOG.md b/CHANGELOG.md index e6f5ece..c29d66a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. [Unreleased] +### Added +- Support for registering example data for ACF Blocks. + ## [1.41.6] ### Added diff --git a/src/Block.php b/src/Block.php index 6ffbc1b..4619add 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. * @@ -466,6 +476,16 @@ public function get_styles() : array { */ public function set_parent( ?array $parent ) : self { $this->parent = $parent; + } + + /** + * 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; } @@ -479,6 +499,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 +617,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 ); }