vinkla / extended-acf

Register advanced custom fields with object-oriented PHP
MIT License
455 stars 61 forks source link

Critical Error - ConditionalLogic #150

Closed Mytraas closed 4 months ago

Mytraas commented 4 months ago

Hi,

PHP Critical error using ConditionalLogic in Repeater.

ACF & Extended ACF updated to the latest version.

This is my code :

<?php
defined('ABSPATH') || exit;

use Extended\ACF\ConditionalLogic;
use Extended\ACF\Fields\Text;
use Extended\ACF\Fields\Group;
use Extended\ACF\Fields\Select;
use Extended\ACF\Fields\TrueFalse;
use Extended\ACF\Fields\Repeater;

        $form_field_options = [
            Text::make(__('Label', 'test'), 'label'),
            Select::make(__('Field Type', 'test'), 'field_type')
                ->choices([
                    'text' => __('Text', 'test'),
                    'email' => __('Email', 'test'),
                    'tel' => __('Phone', 'test'),
                    'url' => __('URL', 'test'),
                    'textarea' => __('Textarea', 'test'),
                    'select' => __('Select', 'test'),
                    'number' => __('Number', 'test'),
                ])
                ->default('text')
                ->required(),
            TrueFalse::make(__('Required', 'test'), 'required'),
            TrueFalse::make(__('Hidden', 'test'), 'hidden'),
            Repeater::make(__('Options', 'test'), 'options')
                ->conditionalLogic([
                    ConditionalLogic::where('field_type', '==', 'select')
                ])
                ->fields([
                    Text::make(__('Label', 'test'), 'label'),
                    Text::make(__('Value', 'test'), 'value'),
                ])
                ->minRows(2)
                ->maxRows(10)
                ->collapsed('label')
                ->button('Add option')
                ->required()
        ];

            Group::make(__('Contact Form - Columns Left', 'test'), 'group_col_left')
                ->fields([
                    Text::make(__('Title', 'test'), 'title'),
                    Repeater::make(__('Form Fields', 'test'), 'form_fields')
                    ->fields($form_field_options)
                    ->minRows(2)
                    ->maxRows(10)
                    ->collapsed('name')
                    ->button('Add field')
                    ->required()
                ]);

            Group::make(__('Contact Form - Columns Right', 'test'), 'group_col_right')
                ->fields([
                    Text::make(__('Title', 'test'), 'title'),
                    Repeater::make(__('Form Fields', 'test'), 'form_fields')
                    ->fields($form_field_options)
                    ->minRows(2)
                    ->maxRows(10)
                    ->collapsed('name')
                    ->button('Add field')
                    ->required()
                ]);
    }
}

The critical Error:

[29-Jun-2024 12:12:41 UTC] PHP Fatal error:  Uncaught Error: Call to a member function get() on array in /Users/user/Work/wordpress/clients/test.local/wp-content/themes/test/vendor/vinkla/extended-acf/src/Fields/Field.php:113
Stack trace:
#0 [internal function]: Extended\ACF\Fields\Field->Extended\ACF\Fields\{closure}(Array)
#1 /Users/user/Work/wordpress/clients/test.local/wp-content/themes/test/vendor/vinkla/extended-acf/src/Fields/Field.php(112): array_map(Object(Closure), Array)
#2 /Users/user/Work/wordpress/clients/test.local/wp-content/themes/test/vendor/vinkla/extended-acf/src/Fields/Field.php(127): Extended\ACF\Fields\Field->get('page_layout_lay...')
#3 [internal function]: Extended\ACF\Fields\Field->Extended\ACF\Fields\{closure}(Object(Extended\ACF\Fields\Repeater))
#4 /Users/user/Work/wordpress/clients/test.local/wp-content/themes/test/vendor/vinkla/extended-acf/src/Fields/Field.php(126): array_map(Object(Closure), Array)
#5 /Users/user/Work/wordpress/clients/test.local/wp-content/themes/test/vendor/vinkla/extended-acf/src/Fields/Field.php(127): Extended\ACF\Fields\Field->get('page_layout_lay...')
#6 [internal function]: Extended\ACF\Fields\Field->Extended\ACF\Fields\{closure}(Object(Extended\ACF\Fields\Repeater))
#7 /Users/user/Work/wordpress/clients/test.local/wp-content/themes/test/vendor/vinkla/extended-acf/src/Fields/Field.php(126): array_map(Object(Closure), Array)
#8 /Users/user/Work/wordpress/clients/test.local/wp-content/themes/test/vendor/vinkla/extended-acf/src/Fields/Field.php(127): Extended\ACF\Fields\Field->get('page_layout_lay...')
#9 [internal function]: Extended\ACF\Fields\Field->Extended\ACF\Fields\{closure}(Object(Extended\ACF\Fields\Group))
#10 /Users/user/Work/wordpress/clients/test.local/wp-content/themes/test/vendor/vinkla/extended-acf/src/Fields/Field.php(126): array_map(Object(Closure), Array)
#11 /Users/user/Work/wordpress/clients/test.local/wp-content/themes/test/vendor/vinkla/extended-acf/src/Fields/Field.php(120): Extended\ACF\Fields\Field->get('page_layout_lay...')
#12 [internal function]: Extended\ACF\Fields\Field->Extended\ACF\Fields\{closure}(Object(Extended\ACF\Fields\Layout))
#13 /Users/user/Work/wordpress/clients/test.local/wp-content/themes/test/vendor/vinkla/extended-acf/src/Fields/Field.php(119): array_map(Object(Closure), Array)
#14 /Users/user/Work/wordpress/clients/test.local/wp-content/themes/test/vendor/vinkla/extended-acf/src/helpers.php(36): Extended\ACF\Fields\Field->get('page_layout')
#15 [internal function]: {closure}(Object(Extended\ACF\Fields\FlexibleContent))
#16 /Users/user/Work/wordpress/clients/test.local/wp-content/themes/test/vendor/vinkla/extended-acf/src/helpers.php(36): array_map(Object(Closure), Array)
#17 /Users/user/Work/wordpress/clients/test.local/wp-content/themes/test/functions/acf/Page.php(67): register_extended_field_group(Array)
#18 /Users/user/Work/wordpress/clients/test.local/wp-includes/class-wp-hook.php(324): test\act_init_acf_page_components(6)
#19 /Users/user/Work/wordpress/clients/test.local/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters(NULL, Array)
#20 /Users/user/Work/wordpress/clients/test.local/wp-includes/plugin.php(517): WP_Hook->do_action(Array)
#21 /Users/user/Work/wordpress/clients/test.local/wp-content/plugins/advanced-custom-fields-pro/acf.php(459): do_action('acf/init', 6)
#22 /Users/user/Work/wordpress/clients/test.local/wp-includes/class-wp-hook.php(324): ACF->init('')
#23 /Users/user/Work/wordpress/clients/test.local/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters(NULL, Array)
#24 /Users/user/Work/wordpress/clients/test.local/wp-includes/plugin.php(517): WP_Hook->do_action(Array)
#25 /Users/user/Work/wordpress/clients/test.local/wp-settings.php(695): do_action('init')
#26 /Users/user/Work/wordpress/clients/test.local/wp-config.php(98): require_once('/Users/user/W...')
#27 /Users/user/Work/wordpress/clients/test.local/wp-load.php(50): require_once('/Users/user/W...')
#28 /Users/user/Work/wordpress/clients/test.local/wp-blog-header.php(13): require_once('/Users/user/W...')
#29 /Users/user/Work/wordpress/clients/test.local/index.php(17): require('/Users/user/W...')
#30 {main}
  thrown in /Users/user/Work/wordpress/clients/test.local/wp-content/themes/test/vendor/vinkla/extended-acf/src/Fields/Field.php on line 113

Thanks for the help.

vinkla commented 4 months ago

Please provide a failing test case in a pull request to demonstrate the error. Thank you.