Folks, Im really starting to lose my mind
Im using the ACF builder, but not ACF Composer-
I’m trying to build a wrapper class that dynamically builds the flexiblecontent which all partials that have been passed through. All “partials” are stored within their own classes.
My issue is, that whenever I break the chain with a semicolon it says “addLayout” is not available.
$fieldsBuilder
->addFlexibleContent('flexible_content_field', [
'label' => $args['label'] ?? 'Flexible Content',
'instructions' => $args['instructions'] ?? '',
'button_label' => $args['button_label'] ?? 'Add Row',
'min' => $args['min'] ?? '',
'max' => $args['max'] ?? ''
])
->addLayout('layout', [
'label' => 'Layout',
'display' => 'block',
'sub_fields' => ['text_example'],
'min' => '',
'max' => '',
])
->addText('text_example', [
'label' => 'Text',
'instructions' => '',
'required' => 0,
'conditional_logic' => [],
'wrapper' => [
'width' => '',
'class' => '',
'id' => '',
],
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'maxlength' => '',
])
->endFlexibleContent()
;
My example Layout Class
<?php
namespace App\Partials;
use StoutLogic\AcfBuilder\FieldsBuilder;
class Content
{
public static function getLayout($fieldsBuilder)
{
return $fieldsBuilder->addLayout('content', [
'label' => 'Content',
'display' => 'block',
'sub_fields' => [],
'min' => '',
'max' => '',
])
->addText('text_example', [
'label' => 'Text',
'instructions' => '',
'required' => 0,
'conditional_logic' => [],
'wrapper' => [
'width' => '',
'class' => '',
'id' => '',
],
]);
}
}
my wrapper class:
<?php
namespace App\Partials\Base;
use StoutLogic\AcfBuilder\FieldsBuilder;
class PartialBuilder
{
public static function buildFlexibleContent($fieldsBuilder, array $partials, $args = [])
{
$test= 'addFlexibleContent';
$fieldsBuilder
->addFlexibleContent('flexible_content_field', [
'label' => $args['label'] ?? 'Flexible Content',
'instructions' => $args['instructions'] ?? '',
'button_label' => $args['button_label'] ?? 'Add Row',
'min' => $args['min'] ?? '',
'max' => $args['max'] ?? ''
])
;
if ($partials) {
foreach ($partials as $partial) {
$methodName = "\\App\\Partials\\" . ucfirst($partial) . "::getLayout";
if (is_callable($methodName)) {
call_user_func($methodName, $fieldsBuilder);
}
}
}
// dd($fieldsBuilder);
return $fieldsBuilder;
}
}