Download the PHP package beblife/acf-gutenberg-blocks without Composer
On this page you can find all versions of the php package beblife/acf-gutenberg-blocks. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download beblife/acf-gutenberg-blocks
More information about beblife/acf-gutenberg-blocks
Files in beblife/acf-gutenberg-blocks
Package acf-gutenberg-blocks
Short Description An elegant way for developers to register Gutenberg blocks using the ACF PRO blocks feature
License MIT
Informations about the package acf-gutenberg-blocks
ACF Gutenberg blocks
An elegant way for developers to register Gutenberg blocks using the Advanced Custom Fields PRO features.
- Installation
- Define blocks
- Register blocks
- Configure fields
- Retrieve data
- Define classes
- Render blocks
Installation
You can install this package through composer:
Define blocks
You can define custom blocks by creating classes that extend the base block class provided by this package.
By extending from the base block enables you to easily define custom blocks with a minimum of configuration:
The base block class configures a few things by default behind the scence for convenience but can be changed easily. The following properties are defined out of the box:
Register blocks
To enable the custom blocks you need to register them by hooking into the acf/init
filter. This allows for a flexible way to define which blocks should be enabled.
You can enable blocks by passing an array with classes:
To automatically register all blocks in a directory can provide the relative path in the current theme:
Defining a parent block
You can define a block to have a parent block by updating the $parent
property on your block class.
This will result in the block being hidden from the blocks list in Gutenberg but only available as a "sub block" for the parent block.
For the child block to be selectable within the parent block you will need to set
$inner_blocks = true
on the parent block.
Configure fields
Fields can be added to a custom block by defining a fields()
method on the class and make it return an array of fields to add.
This package includes wordplate/extended-acf to define fields for a block in an easy and elegant way. Make sure to read the documentation to see which field types are available.
Below you can find an example of how you can define fields using this package:
Retrieve data
To retrieve the data from the defined fields you have a few options.
Define classes
By default a few classes are added to the wrapper HTML-element to be able to add general styles and specific styles for blocks and respect the alignment and other input from the Gutenberg editor.
You can override or extend the classes that are added by defining your own classes
method:
Please note that when overriding the default classes some Gutenberg behaviour will no longer work and will have to be added from the
$block
parameter to prevent this from happening!
Render blocks
All blocks require a render()
method to be implemented. The way you render a block is up to you, an example with Wordpress' get_template_part()
is given below:
License
Laurens Bultynck