Skip to content
Grav 2.0 is officially stable. Read the announcement →
Themes & Styling

Taxonomy "GRAV" results in Array to String conversion error

Solved by pamtbaau View solution

Started by Marcus 5 years ago · 3 replies · 613 views
5 years ago

Hi folks,
I'm currently creating a Grav theme and filling in some content.
While testing the taxonomy feature, I ran into a funny bug:

If you add the string GRAV (just GRAV, uppercase) to any page's taxonomies, the admin plugin crashes and it's not possible to edit any page any more. Removing "GRAV" fixes it.

TXT
 Twig \ Error \ RuntimeError
An exception has been thrown during the rendering of a template ("Array to string conversion").
Previous exceptions

    Array to string conversion (8)

Stack frames (167)
166
Twig\Error\RuntimeError
…/user/plugins/form/templates/forms/fields/select/select.html.twig65
165
Whoops\Exception\ErrorException
…/cache/twig/11/1139bc0d96d52c6565fe4d1905f3e0017ba1f26de2cb43a3b356090029e44ca4.php289

Steps to reproduce:
-Add a page
-Frontmatter:

YAML
---
title: 'This is a test page'
taxonomy:
    tag:
        - TYPO3
        - Backend
        - GRAV-CMS
        - GRAV
        - Test
---

-Try to edit a page in admin

5 years ago

@atnetws, As you can see in template /user/plugins/form/templates/forms/fields/select/select.html.twig on line 65, the template tries to translate the value:

TWIG
{{ item_value|t|raw }}

And the value GRAV is mentioned in file `/system/languages/*.yaml' and is an array. Hence the error "Array to string conversation"

Solution:

  • Don't use value GRAV or any other value that is an array in any language file.
  • Translations are case-sensitive, so Grav does not throw an error.
5 years ago

Hi Pamtbaau,
yes, the reason is quite obvious, but avoiding reserved words cannot be the solution. An editor should not be able to crash the application by just adding a content into the tag field. You can't explain non-technicans that they're not allowed to tag the product's name they're using.

5 years ago Solution

@atnetws, The chances of the error occuring is slim since Grav has set a convention to add namespaces in translation files. See https://learn.getgrav.org/17/content/multi-language#plugin-and-theme-language-translations

The convention for plugins is to use PLUGIN_PLUGINNAME. as a prefix for all language strings, to avoid any name conflict. Themes are less likely to introduce language strings conflicts, but it's a good idea to prefix strings added in themes with THEME_THEMENAME.

The namespace for Grav internals is GRAV. Which is unfortunate in your use-case.

Having said that, Grav seems to be using Taxonomy values untranslated as does Quark and plugin TaxonomyList. It seems that values of a Taxonomy field shouldn't be translated at all.

I've added an issue in the Form repo to note this.

👍 1
last edited 09/25/21 by pamtbaau

Suggested topics

Topic Participants Replies Views Activity
Themes & Styling · by Pedro M, 2 months ago
4 226 2 months ago
Themes & Styling · by Ian, 2 months ago
3 119 2 months ago
Themes & Styling · by Norbert, 2 years ago
11 483 3 months ago
Themes & Styling · by Lukáš Findeis, 3 months ago
0 73 3 months ago
Themes & Styling · by Sebadamus, 4 months ago
5 152 3 months ago