Log1x / acf-composer

Compose ACF Fields, Blocks, Widgets, and Option Pages with ACF Builder on Sage 10.
https://github.com/Log1x/acf-composer
MIT License
400 stars 53 forks source link

Feature request: Add partials multiple times #189

Closed Schwankenson closed 6 months ago

Schwankenson commented 6 months ago

Hi, I would like to add a partials multiple time with different field name. I think the $this->get function from InteractsWithPartial trait would need a second parameter where you can pass a assoziative array which can then be used for field generation.

Or is this possible in another way?

What I would do with it: I have a complex partial which contains 3 fields, and I would like to add it multiple times to one block. But not as repeater.

Log1x commented 6 months ago

I would probably put the fields in a method inside of a Trait that accepts/handles the array and then use that trait's method to add the fields to the builder.

I have a bigger update started for ACF Composer to make some of this stuff (hopefully) a lot nicer, but no ETA right now.

Schwankenson commented 6 months ago

Great!

I now ended up in adding the parameters to the fields function of the partials:

public function fields($bootstrap_class_prefix="pb", $field_name_postfix="pb", $conditional_logic=[])
{
(...)
}

Then I render it like this:

$partialClass = new BootstrapSpacingClasses($this->app);
$renderedPartialFieldsSizeClassPb = $partialClass->fields("abc", "def");

And put it to the block with ->addFields($renderedPartialFieldsSizeClassPb)

That works great and does exactly what I want.