Log1x / acf-composer

Compose ACF Fields, Blocks, Widgets, and Option Pages with ACF Builder on Sage 10.
https://github.com/Log1x/acf-composer
MIT License
400 stars 53 forks source link

Unable to end Groups and Repeaters with `addPartial()` inside #197

Closed thunderdw closed 4 months ago

thunderdw commented 4 months ago

When using addPartial() inside of a repeater or group field, an exception is thrown. This is happening on v3.0.1.

app/Fields/ExampleField.php:

<?php

namespace App\Fields;

use App\Fields\Partials\ExamplePartial;
use Log1x\AcfComposer\Builder;
use Log1x\AcfComposer\Field;

class ExampleField extends Field
{
    /**
     * The field group.
     *
     * @return array
     */
    public function fields()
    {
        $exampleField = Builder::make('example_field');

        $exampleField
            ->setLocation('post_type', '==', 'post');

        $exampleField
            ->addRepeater('items')
                ->addPartial(ExamplePartial::class)
            ->endRepeater()
            ->addText('some_field');

        return $exampleField->build();
    }
}

app/Fields/Partials/ExamplePartial.php

<?php

namespace App\Fields\Partials;

use Log1x\AcfComposer\Builder;
use Log1x\AcfComposer\Partial;

class ExamplePartial extends Partial
{
    /**
     * The partial field group.
     *
     * @return \Log1x\AcfComposer\Builder
     */
    public function fields()
    {
        $examplePartial = Builder::make('example_partial');

        $examplePartial
            ->addText('example_field');

        return $examplePartial;
    }
}

Stack trace:

Exception thrown with message "No such function: endRepeater"

Stacktrace:
#22 Exception in /app/vendor/stoutlogic/acf-builder/src/ParentDelegationBuilder.php:69
#21 StoutLogic\AcfBuilder\ParentDelegationBuilder:__call in /app/vendor/log1x/acf-composer/src/Builder.php:108
#20 Log1x\AcfComposer\Builder:__call in /app/app/Fields/ExampleField.php:26
#19 App\Fields\ExampleField:fields in /app/vendor/log1x/acf-composer/src/Composer.php:95
#18 Log1x\AcfComposer\Composer:getFields in /app/vendor/log1x/acf-composer/src/Composer.php:53
#17 Log1x\AcfComposer\Composer:__construct in /app/vendor/log1x/acf-composer/src/Composer.php:61
#16 Log1x\AcfComposer\Composer:make in /app/vendor/log1x/acf-composer/src/AcfComposer.php:169
#15 Log1x\AcfComposer\AcfComposer:register in /app/vendor/log1x/acf-composer/src/AcfComposer.php:148
#14 Log1x\AcfComposer\AcfComposer:registerPath in /app/vendor/log1x/acf-composer/src/AcfComposer.php:109
#13 Log1x\AcfComposer\AcfComposer:registerDefaultPath in /app/vendor/log1x/acf-composer/src/AcfComposer.php:87
#12 Log1x\AcfComposer\AcfComposer:boot in /app/vendor/log1x/acf-composer/src/AcfComposer.php:79
#11 Log1x\AcfComposer\AcfComposer:Log1x\AcfComposer\{closure} in /app/public/wp/wp-includes/class-wp-hook.php:324
#10 WP_Hook:apply_filters in /app/public/wp/wp-includes/class-wp-hook.php:348
#9 WP_Hook:do_action in /app/public/wp/wp-includes/plugin.php:517
#8 do_action in /app/public/content/mu-plugins/advanced-custom-fields-pro/acf.php:397
#7 ACF:init in /app/public/wp/wp-includes/class-wp-hook.php:324
#6 WP_Hook:apply_filters in /app/public/wp/wp-includes/class-wp-hook.php:348
#5 WP_Hook:do_action in /app/public/wp/wp-includes/plugin.php:517
#4 do_action in /app/public/wp/wp-settings.php:643
#3 require_once in /app/public/wp-config.php:11
#2 require_once in /app/public/wp/wp-load.php:55
#1 require_once in /app/public/wp/wp-blog-header.php:13
#0 require in /app/public/index.php:9
Log1x commented 4 months ago

Does this still work when doing it the old way? (->addFields($this->get(...)))

thunderdw commented 4 months ago

Yes, still works the old way

         $exampleField
             ->addRepeater('items')
-                ->addPartial(ExamplePartial::class)
+                ->addFields($this->get(ExamplePartial::class))
             ->endRepeater()
             ->addText('some_field');
Log1x commented 4 months ago

I see. I will have to extend ACF Builder's FieldBuilder and override a few other classes in the Builder to get parent context working properly when extending FieldsBuilder.

Thanks for reporting, I will get it fixed tonight.