I don’t normally make posts about releases but this one ended up being a lot larger than expected so I’d like to open up an easy way for people to ask questions or get support specific to the release.
Check out the full release notes here: Release v3.0.0 · Log1x/acf-composer · GitHub
Breaking Change
If you generated Blocks using the --construct
option, you will need to manually update the block __construct()
's with a find & replace:
- use Roots\Acorn\Application;
+ use Log1x\AcfComposer\AcfComposer;
- public function __construct(Application $app)
+ public function __construct(AcfComposer $composer)
- parent::__construct($app);
+ parent::__construct($composer);
Once done, continue to the upgrade guide below.
Upgrade Guide
- Make sure ACF Composer is installed in the same
composer.json
as Acorn. - Run
composer require log1x/acf-composer
to upgrade to^3.0
. - Update your class references using
wp acorn acf:upgrade
.
Going forward, it is recommended to use the new Builder
class:
- use StoutLogic\AcfBuilder\FieldsBuilder;
+ use Log1x\AcfComposer\Builder;
- $listItems = new FieldsBuilder('listItems');
+ $listItems = Builder::make('listItems');
When using the new Builder
class, you can now use ->addPartial()
to add field partials:
- $listItems->addFields($this->get(Partial::class));
+ $listItems->addPartial(Partial::class);
Inside of Blocks, enqueue()
has been changed to assets($block)
:
- public function enqueue()
+ public function assets($block)
Running wp acorn acf:upgrade
should do all of the above for you automatically.
Config Changes
There are 2 new entries to the acf.php
config if you have it published:
/*
|--------------------------------------------------------------------------
| Custom Field Types
|--------------------------------------------------------------------------
|
| Here you can define custom field types that are not included with ACF
| out of the box. This allows you to use the fluent builder pattern with
| custom field types such as `addEditorPalette()`.
|
*/
'types' => [
// 'editorPalette' => 'editor_palette',
// 'phoneNumber' => 'phone_number',
],
/*
|--------------------------------------------------------------------------
| Cache Manifest Path
|--------------------------------------------------------------------------
|
| Here you can define the cache manifest path. Fields are typically cached
| when running the `acf:cache` command. This will cache the built field
| groups and potentially improve performance in complex applications.
|
*/
'manifest' => storage_path('framework/cache'),
Field Group Caching
ACF Composer now includes field group caching. It may be a good idea to add this to your deployment script, especially if you have a lot of field groups:
$ wp acorn acf:cache
You can view the status of the cache by running wp acorn acf:cache --status
or wp acorn about
.
Custom Field Types
Seen in the config changes above is support for adding custom field types to the Builder. This should help tidy up code a bit when using custom types like ACF Phone Number and ACF Editor Palette.
Once defined in config/acf.php
, you can generate IDE helpers for them using wp acorn acf:ide-helpers
.
- $fields->addField('mobile_number', 'phone_number');
+ $fields->addPhoneNumber('mobile_number');