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

no such function addLayout? #148

Open
broskees opened this issue Dec 5, 2021 · 1 comment
Open

no such function addLayout? #148

broskees opened this issue Dec 5, 2021 · 1 comment

Comments

@broskees
Copy link

broskees commented Dec 5, 2021

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
Copy link
Author

broskees commented Dec 5, 2021

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;

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

1 participant