Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flexible content and repeater fatal error #154

Open
alexadark opened this issue Jun 19, 2022 · 2 comments
Open

Flexible content and repeater fatal error #154

alexadark opened this issue Jun 19, 2022 · 2 comments

Comments

@alexadark
Copy link

alexadark commented Jun 19, 2022

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 alexadark changed the title Flexible content error Flexible content and repeater fatal error Jun 19, 2022
@stevep
Copy link
Member

stevep commented Jun 20, 2022

@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:

if (!isset($config['button_label'])) {
$this->setConfig('button_label', $this->getDefaultButtonLabel());
}

private function getDefaultButtonLabel()
{
return 'Add ' . $this->singularize($this->getLabel());
}

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());
});

@alexadark
Copy link
Author

Thanks! everything works now!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants