Taxonomy "GRAV" results in Array to String conversion error

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.

 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:

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

-Try to edit a page in admin

@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:

{{ 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.

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.

@atnetws, The chances of the error occuring is slim since Grav has set a convention to add namespaces in translation files. See Multi-Language | Grav Documentation

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 Like