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

Argument 4 passed to Grav\Plugin\Form\TwigExtension::prepareFormField() must be of the type array #2177

Closed
salgua opened this issue Sep 1, 2021 · 7 comments
Assignees

Comments

@salgua
Copy link

salgua commented Sep 1, 2021

After the upgrade to v5.1.0, editing a page from admin panel I receive the following error:

Argument 4 passed to Grav\Plugin\Form\TwigExtension::prepareFormField() must be of the type array, string given

Grav and all plugins are to latest available version. PHP is 7.4

@mahagr
Copy link
Member

mahagr commented Sep 1, 2021

Can you see where the error comes from? If you enable debugger, you should be able to see the full backtrace.

@mahagr mahagr self-assigned this Sep 1, 2021
@salgua
Copy link
Author

salgua commented Sep 1, 2021

Sorry... it comes from:

Argument 4 passed to Grav\Plugin\Form\TwigExtension::prepareFormField() must be of the type array, string given, called in ..../cache/twig/e1/e1c19b537f943e3c2da59d00cbbb0bac95bb2882df307317d9a0fed91f884da5.php on line 217

...

 user/plugins/form/classes/TwigExtension.php

row from 72 to 91

    {
    // Make sure that the field is a valid form field type and is not being ignored.
    if (empty($field['type']) || ($field['validate']['ignore'] ?? false)) {
        return null;
    }

    // Check if we have just a list of fields (no name given).
    if (is_int($name)) {
        $name = null;
    }

    // Make sure that the field has a name.
    $name = $name ?? $field['name'] ?? null;
    if (!is_string($name) || $name === '') {
        return null;
    }

    // Prefix name with the parent name if needed.
    if (str_starts_with($name, '.')) {
        $name = $parent ? $parent . $name : (string)substr($name, 1);

@mahagr
Copy link
Member

mahagr commented Sep 1, 2021

What I am interested in is that Twig file /cache/twig/e1/e1c19b537f943e3c2da59d00cbbb0bac95bb2882df307317d9a0fed91f884da5.php should have a comment on what the real twig filename is and if you go to line 217, there should be a comment above it to tell the line where it happens.

@salgua
Copy link
Author

salgua commented Sep 1, 2021

here the comment:

/* forms/fields/fieldset/fieldset.html.twig */

then at the end of the file I find:

user/plugins/admin/themes/grav/templates/forms/fields/fieldset/fieldset.html.twig

but the file has fewer than 217 rows

@mahagr
Copy link
Member

mahagr commented Sep 1, 2021

Try to change fieldset line 57 to:

{% set child = prepare_form_field(child, child_name, field.name, {key: key}) %}

That should fix the issue.

@salgua
Copy link
Author

salgua commented Sep 1, 2021

it works!
Thank you very much!

@mahagr
Copy link
Member

mahagr commented Sep 1, 2021

Let me move this issue to admin as the issue is in there.

@mahagr mahagr transferred this issue from getgrav/grav-plugin-form Sep 1, 2021
@mahagr mahagr added the bug label Sep 1, 2021
mahagr added a commit that referenced this issue Sep 1, 2021
…::prepareFormField() must be of the type array` [#2177]
@mahagr mahagr changed the title Error editing page from admin interface after 5.1.0 update Argument 4 passed to Grav\Plugin\Form\TwigExtension::prepareFormField() must be of the type array Sep 1, 2021
@mahagr mahagr added the fixed label Sep 1, 2021
@mahagr mahagr closed this as completed Sep 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants