Hi,
I’m using acf-composer and working on partials for my blocks. One of these partials is to reuse a Headline partial multiple times in a block, but each instance needs a unique key/name as otherwise it gives me error ofcourse.
From my findings the usual fields() method doesn’t get any arguments, because it’s called during the parent constructor. So the key I pass via addPartial(Headline::class, ['name' => 'headline_1']) isn’t available there.
Currently, the only way I’ve got it working is by building all fields inside compose($args) instead of fields(). This seems to work but feels like a hacky way of doing it and my cause problems in the future?
<?php
namespace App\Fields\Partials;
use Log1x\AcfComposer\Builder;
use Log1x\AcfComposer\Partial;
class Headline extends Partial
{
public function compose(array $args = []): Builder
{
$key = $args['name'];
return Builder::make($key)
->addGroup($key, ['label' => 'Headline'])
->addText('text', ['label' => 'Text'])
->addSelect('type', [
'label' => 'Type',
'choices' => ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'],
'ui' => 1,
'allow_null' => 1,
'return_format' => 'value',
'placeholder' => 'Select headline type',
])
->endGroup();
}
}
My question: is there a simpler or built-in way to assign a custom key/name to partial instances without having to do this?
Thanks!