Grav-plugin-admin: "Array to string conversion" exception when saving a page with field type "pages" and "multiple: true"

Created on 16 Mar 2017  路  10Comments  路  Source: getgrav/grav-plugin-admin

Tested on new installs of

  • Grav v1.1.17 - Admin v1.2.14
  • Grav v1.2.0-rc.1 - Admin v1.3.0-rc.1

Environment:

  • macOS 10.12.3
  • Safari 10.0.3
  • localhost (with MAMP PRO)
  • PHP 7.1

Repro steps:

  1. Install Grav with the admin plugin.
  2. Open system/blueprints/pages/default.yaml (just for speed, but I can reproduce the bug with a page blueprint found in a theme as well)
  3. In the content tab, add this field (line 38):
            header.content.items:
              label: Pages
              type: pages
              multiple: true
  1. Edit the Home page through the admin panel.
  2. In the "Content" tab, scroll to the bottom and enter "Home" in the "Pages" field. Select the Home page from the dropdown so it becomes a token in the input.
  3. Try to save the page.

Expected result: No error.
Actual result:

Whoops \ Exception \ ErrorException (E_NOTICE)
Array to string conversion

This does not happen if the field doesn't have multiple: true. I also tried adding validation: type: array but it doesn't fix it.

bug

Most helpful comment

I have the same problem with filepicker or pagemediaselect when saving i've got this error.
capture d ecran 2017-06-09 a 11 06 29

And if i add validate type commalist i have this error :

capture d ecran 2017-06-09 a 11 11 30

All 10 comments

Update: This error doesn't occur when

validation:
  type: commalist

is added to the field in the blueprint.

FYI, you shouldn't be modifying the system blueprints. If you want to add a field you should do it with an override. Look at the antimatter theme in the blueprints/pages folder for some relevant examples.

I know, this happens when doing it in a theme as well. So this is not considered a bug? I think at least the error message could be a little more helpful.

hmm.. I guess we could auto-handle forcing comma list in pages field when multiple is true.. I'll open her up again.

Can confirm that this is a bug, and that adding:

validate:  # NOT `validation`
  type: commalist

to the field in question does seem to work for my case. The field in its entirety being:

            header.associated_products:
              type: pages
              multiple: true
              label: Products applicable for this warranty
              validate:
                type: commalist

To reproduce the exception OP was talking about, just remove the two lines beginning at validate and try to save the page.

I have the same problem with filepicker or pagemediaselect when saving i've got this error.
capture d ecran 2017-06-09 a 11 06 29

And if i add validate type commalist i have this error :

capture d ecran 2017-06-09 a 11 11 30

I got the exact same problem as @Amorfx. Any update about this bug?

I would like to use pagemediaselect field with attribute multiple to true. (as the doc say, it's possible)

I tried to add a field like this from a blueprint:

header.hero_images:
              ordering@: 2
              type: pagemediaselect
              multiple: true
              label: Choose header image
              style: vertical
              preview_images: true
              accept:
                - .jpg
                - .png

As suggested above, I've also tried to add:

validation:
  type: commalist

Sadly nothing work I always get a Twig_Error_Runtime: An exception has been thrown during the rendering of a template ("Array to string conversion").

Hello there,

I get the same error when using the "filepicker" field inside a config yaml file. Is there any new insight on this problem?

Hi there

I have the same problem with pagemediaselect.

Before adding the validate part I get the Array to string conversion error mentioned previously. After adding it i get another one but this time in twig (same as @Amorfx ).

My setup:

header.gallery:
  type: pagemediaselect
  label: Gallery
  multiple: true
  validate:
    type: commalist
Was this page helpful?
0 / 5 - 0 ratings

Related issues

darkroastcreative picture darkroastcreative  路  4Comments

illycz picture illycz  路  5Comments

WilliamMiceli picture WilliamMiceli  路  4Comments

coolemur picture coolemur  路  3Comments

danzinger picture danzinger  路  5Comments