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

"Array to string conversion" exception when saving a page with field type "pages" and "multiple: true" #1024

Open
benface opened this issue Mar 16, 2017 · 10 comments
Assignees
Labels

Comments

@benface
Copy link

benface commented Mar 16, 2017

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.

@benface
Copy link
Author

benface commented Mar 17, 2017

Update: This error doesn't occur when

validation:
  type: commalist

is added to the field in the blueprint.

@rhukster
Copy link
Member

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.

@benface
Copy link
Author

benface commented Mar 18, 2017

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.

@rhukster
Copy link
Member

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

@rhukster rhukster reopened this Mar 18, 2017
@rhukster rhukster added the bug label Apr 13, 2017
@baublet
Copy link

baublet commented Apr 25, 2017

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.

@Amorfx
Copy link

Amorfx commented Jun 9, 2017

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

@jimblue
Copy link

jimblue commented Jan 18, 2018

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

@jimblue
Copy link

jimblue commented Mar 21, 2018

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").

@mgollmer
Copy link

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?

@zampage
Copy link

zampage commented Nov 7, 2018

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

@mahagr mahagr self-assigned this Dec 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

8 participants