acf-builder icon indicating copy to clipboard operation
acf-builder copied to clipboard

Flexible content and repeater fatal error

Open alexadark opened this issue 3 years ago • 2 comments

Hello, I'm trying to add flexible content, and it gives errors, even by pasting the example

use StoutLogic\AcfBuilder\FieldsBuilder;
$content = new FieldsBuilder('page_content');
$content
    ->addFlexibleContent('sections')
        ->addLayout('banner')
            ->addText('title')
            ->addWysiwyg('content')
        ->addLayout('content_columns')
            ->addRepeater('columns', ['min' => 1, 'max' => 2])
                ->addWysiwyg('content');

add_action('acf/init', function() use ($content) {
     acf_add_local_field_group($content->build());
         });

This is what happens on the WordPress side Fatal error: Uncaught Error: Class 'Doctrine\Common\Inflector\Inflector' not found in /Users/alexandraspalato/Local Sites/agencytheme/app/public/wp-content/plugins/headlesswp-core/acf-builder/src/Traits/CanSingularize.php on line 18

Same thing happens with the repeater field

I'm much more a react dev, than PHP, but this is the example, so it should work... I don't use composer, so I have installed acf-builder with autoload

alexadark avatar Jun 19 '22 12:06 alexadark

@alexadark Ah I see, ACF builder is relying on the 3rd party library to handle the automatic singular of a word for the button labels in the Flexible Content and Repeater field types. But if you don't have it installed with composer or installed manually it will fail. Probably not the best developer experience.

The good thing is, it will only attempt to do so if button_label isn't passed in the field config. See: https://github.com/StoutLogic/acf-builder/blob/e63ab87233ea3675cd519f1dd6b6d4230b3cef97/src/FlexibleContentBuilder.php#L28-L30

https://github.com/StoutLogic/acf-builder/blob/e63ab87233ea3675cd519f1dd6b6d4230b3cef97/src/FlexibleContentBuilder.php#L176-L179

So you should be able to pass it in, try:

use StoutLogic\AcfBuilder\FieldsBuilder;
$content = new FieldsBuilder('page_content');
$content
    ->addFlexibleContent('sections', ['button_label' => 'Add Section'])
        ->addLayout('banner')
            ->addText('title')
            ->addWysiwyg('content')
        ->addLayout('content_columns')
            ->addRepeater('columns', ['min' => 1, 'max' => 2])
                ->addWysiwyg('content');

add_action('acf/init', function() use ($content) {
     acf_add_local_field_group($content->build());
});

stevep avatar Jun 20 '22 01:06 stevep

Thanks! everything works now!

alexadark avatar Jun 20 '22 05:06 alexadark