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

no such function addLayout?

Open broskees opened this issue 3 years ago • 1 comments

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 avatar Dec 05 '21 01:12 broskees

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;

broskees avatar Dec 05 '21 02:12 broskees