vinkla / extended-acf

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

Calling ->dump() on a field with sub_fields always returns error #153

Open marcoluzi opened 2 months ago

marcoluzi commented 2 months ago

Description of the bug

Using ->dump() on a Field that has sub_fields always return the following error:

Fatal error: Uncaught Error: Call to a member function get() on array

The dump itself is returned but the error happens afterwards.

Screenshot 2024-08-16 at 14 30 56

Dumps on other fields are returned without any errors. Also tested on the Repeater field with the same resulting error as above.

Steps to reproduce

register_extended_field_group([
    'title' => 'Kundeninformationen',
    'fields' => [
        Image::make('Logo'),
        Text::make('Firmenname'),
        Text::make('Strasse/Nr.'),
        Text::make('PLZ'),
        Text::make('Ort'),
        Text::make('Telefon'),
        Group::make('Social Media')
            ->fields([
                URL::make('Facebook'),
                URL::make('Instagram'),
                URL::make('LinkedIn'),
                URL::make('X'),
                URL::make('YouTube'),
            ])->dump(),
    ],
    'location' => [Location::where('post_type', 'page')],
]);
vinkla commented 2 months ago

I can confirm the issue. This occurs because we convert the sub_fields into an array within the get method. The next time it runs, the array is already converted. To address this, we could maybe clone the current field instance before processing it. Feel free to submit a pull request!

marcoluzi commented 2 months ago

@vinkla I tested the changes in the PR using the PHPUnit tests provided in the repo. No errors were found. However, since I lack the overall picture of the tool, I would be glad to receive any feedback regarding my changes.