StoutLogic / acf-builder

An Advanced Custom Field Configuration Builder
GNU General Public License v2.0
794 stars 62 forks source link

no such function addLayout? #148

Open broskees opened 2 years ago

broskees commented 2 years ago

Can't for the life of me figure out why I'm getting this error.

<?php

namespace Lib;

use StoutLogic\AcfBuilder\FieldsBuilder;

$content = new FieldsBuilder('single_client_results');

$content
    ->setLocation('post_type', '==', 'client-results');

$content
    ->addTab(__('Client Info', 'zoey'))
        ->addImage('client_logo')
        ->addWysiwyg('client_description')
    ->addTab(__('Case Study Info', 'zoey'))
        ->addWysiwyg('the_problem')
        ->addWysiwyg('the_solution')
        ->addWysiwyg('the_results')
        ->addImage('victory_image', [
            'instructions' => __('This image is displayed alongside "The Results" field. It should be an image of the client in a state of victory after the solution has impacted their business.', 'zoey')
        ])
    ->addTab(__('Work Samples', 'zoey'))
        ->addFlexibleContent('work_samples');

foreach(
    get_posts([
        'post_type' => 'services',
        'number_posts' => -1
    ]) as $service
) {
    $content
        ->modifyField('work_samples', function($fieldsbuilder) {
            $fieldsbuilder
                ->addLayout($service->post_name, ['label' => $service->post_title])
                    ->addText('title', ['default_value' => $service->post_title])
                    ->addFields(
                        field_partial_exists("layouts.$service->post_name") ?
                        get_field_partial("layouts.$service->post_name") :
                        get_field_partial('layouts.gallery')
                    );

            return $fieldsbuilder;
        });
}

return $content;

gives me the error: PHP message: PHP Fatal error: Uncaught Exception: No such function: addLayout in ...vendor/stoutlogic/acf-builder/src/ParentDelegationBuilder.php:69

broskees commented 2 years ago

I figured it out after hours of screwing with this:

<?php

namespace Lib;

use StoutLogic\AcfBuilder\FieldsBuilder;

$content = new FieldsBuilder('single_client_results');

$content
    ->setLocation('post_type', '==', 'client-results');

$content
    ->addTab(__('Client Info', 'zoey'))
        ->addImage('client_logo')
        ->addWysiwyg('client_description')
    ->addTab(__('Case Study Info', 'zoey'))
        ->addWysiwyg('the_problem')
        ->addWysiwyg('the_solution')
        ->addWysiwyg('the_results')
        ->addImage('victory_image', [
            'instructions' => __('This image is displayed alongside "The Results" field. It should be an image of the client in a state of victory after the solution has impacted their business.', 'zoey')
        ])
    ->addTab(__('Work Samples', 'zoey'))
        ->addFlexibleContent('work_samples');

foreach(
    get_posts([
        'post_type' => 'services',
        'number_posts' => -1
    ]) as $service
) {
    $content
        ->getField('work_samples')
            ->addLayout($service->post_name, ['label' => $service->post_title])
                ->addText('title', ['default_value' => $service->post_title])
                ->addFields(
                    field_partial_exists("layouts.$service->post_name") ?
                    get_field_partial("layouts.$service->post_name") :
                    get_field_partial('layouts.gallery')
                );
}

return $content;