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

Error message 'can't convert array to string' when using content.order.by with a taxonomy #1264

Closed
nineteeneightyeight opened this issue Jan 20, 2017 · 6 comments

Comments

@nineteeneightyeight
Copy link

nineteeneightyeight commented Jan 20, 2017

Previously (and currently when testing locally) the live environment of our site would allow us to order the collection by the taxonomy. This meant that we could group together particular tags - each article would only have one tag. I appreciate that this could then create an array, and therefore the error message could appear, but this never used to happen (is this by pure happenstance?) and still doesn't happen on my local environment. In fact, Flavio has also tested the site, and it doesn't occur for him locally either.

To prevent the error showing on the front end for now, I have set it to order.by:default. However, I can break it again to show you if requested.

Steps taken to isolate the error so far include:

  • Upgraded PHP version from 5.5.9 to 7.0
  • Downgraded Admin plugin to 1.2.4 from latest
  • Downgraded Grav to 1.1.9 from latest
  • Used live backup to test site locally on Flavio and my local environments - (can't reproduce)

For reference the stack trace I was getting is as follows:

Twig_Error_Runtime thrown with message "An exception has been thrown during the rendering of a template ("Array to string conversion")."

Stacktrace:
#37 Twig_Error_Runtime in /home/grav/www/html/user/plugins/admin/themes/grav/templates/pages.html.twig:57
#36 Whoops\Exception\ErrorException in /home/grav/www/html/system/src/Grav/Common/Page/Pages.php:1115
#35 asort in /home/grav/www/html/system/src/Grav/Common/Page/Pages.php:1115
#34 Grav\Common\Page\Pages:buildSort in /home/grav/www/html/system/src/Grav/Common/Page/Pages.php:248
#33 Grav\Common\Page\Pages:sortCollection in /home/grav/www/html/system/src/Grav/Common/Page/Collection.php:180
#32 Grav\Common\Page\Collection:order in /home/grav/www/html/vendor/twig/twig/lib/Twig/Template.php:674
#31 call_user_func_array in /home/grav/www/html/vendor/twig/twig/lib/Twig/Template.php:674
#30 Twig_Template:getAttribute in /home/grav/www/html/cache/twig/e9/e9da0732dac06c3f348e28fa732f9839c20463d62583743955142588e1571b27.php:734
#29 __TwigTemplate_5e64f782dd484d82e6ae8fa68439774724f0569b40b6c918c82515eda0cbde4c:getloop in /home/grav/www/html/vendor/twig/twig/lib/Twig/Template.php:674
#28 call_user_func_array in /home/grav/www/html/vendor/twig/twig/lib/Twig/Template.php:674
#27 Twig_Template:getAttribute in /home/grav/www/html/cache/twig/e9/e9da0732dac06c3f348e28fa732f9839c20463d62583743955142588e1571b27.php:865
#26 __TwigTemplate_5e64f782dd484d82e6ae8fa68439774724f0569b40b6c918c82515eda0cbde4c:getloop in /home/grav/www/html/vendor/twig/twig/lib/Twig/Template.php:674
#25 call_user_func_array in /home/grav/www/html/vendor/twig/twig/lib/Twig/Template.php:674
#24 Twig_Template:getAttribute in /home/grav/www/html/cache/twig/e9/e9da0732dac06c3f348e28fa732f9839c20463d62583743955142588e1571b27.php:550
#23 __TwigTemplate_5e64f782dd484d82e6ae8fa68439774724f0569b40b6c918c82515eda0cbde4c:block_content in /home/grav/www/html/vendor/twig/twig/lib/Twig/Template.php:215
#22 Twig_Template:displayBlock in /home/grav/www/html/cache/twig/08/08a879ed4d6c7b83a20deb10f3db40646e3d31fbec80fdb5801cf89a16f83782.php:205
#21 __TwigTemplate_376c17ff3c287d3171ec0d56df0015b11bbe2c5a571377dc3eb48bba3de4a5e8:block_page in /home/grav/www/html/vendor/twig/twig/lib/Twig/Template.php:215
#20 Twig_Template:displayBlock in /home/grav/www/html/cache/twig/08/08a879ed4d6c7b83a20deb10f3db40646e3d31fbec80fdb5801cf89a16f83782.php:158
#19 __TwigTemplate_376c17ff3c287d3171ec0d56df0015b11bbe2c5a571377dc3eb48bba3de4a5e8:block_body in /home/grav/www/html/vendor/twig/twig/lib/Twig/Template.php:215
#18 Twig_Template:displayBlock in /home/grav/www/html/cache/twig/08/08a879ed4d6c7b83a20deb10f3db40646e3d31fbec80fdb5801cf89a16f83782.php:45
#17 __TwigTemplate_376c17ff3c287d3171ec0d56df0015b11bbe2c5a571377dc3eb48bba3de4a5e8:doDisplay in /home/grav/www/html/vendor/twig/twig/lib/Twig/Template.php:432
#16 Twig_Template:displayWithErrorHandling in /home/grav/www/html/vendor/twig/twig/lib/Twig/Template.php:403
#15 Twig_Template:display in /home/grav/www/html/cache/twig/e9/e9da0732dac06c3f348e28fa732f9839c20463d62583743955142588e1571b27.php:73
#14 __TwigTemplate_5e64f782dd484d82e6ae8fa68439774724f0569b40b6c918c82515eda0cbde4c:doDisplay in /home/grav/www/html/vendor/twig/twig/lib/Twig/Template.php:432
#13 Twig_Template:displayWithErrorHandling in /home/grav/www/html/vendor/twig/twig/lib/Twig/Template.php:403
#12 Twig_Template:display in /home/grav/www/html/vendor/twig/twig/lib/Twig/Template.php:411
#11 Twig_Template:render in /home/grav/www/html/vendor/twig/twig/lib/Twig/Environment.php:362
#10 Twig_Environment:render in /home/grav/www/html/system/src/Grav/Common/Twig/Twig.php:348
#9 Grav\Common\Twig\Twig:processSite in /home/grav/www/html/system/src/Grav/Common/Service/OutputServiceProvider.php:18
#8 Grav\Common\Service\OutputServiceProvider:Grav\Common\Service\{closure} in /home/grav/www/html/vendor/pimple/pimple/src/Pimple/Container.php:113
#7 Pimple\Container

cc/ @flaviocopes

@flaviocopes
Copy link
Contributor

I have tested this, we both cannot replicate locally the problem, with the same user/ folder that causes the problem on the server.

@rhukster
Copy link
Member

Can you provide the exact code you are using so i can take a look?

@nineteeneightyeight
Copy link
Author

Sure, so it errors in two places. The admin areas when you try and accessing the 'pages' section, and the front end 'case-studies' page errors.

Within the case-studies frontmatter we have:

content:
    items: '@self.children'
    order:
        by: header.taxonomy.category
        dir: asc

You can see the frontend error message here: https://www.draytonpartners.com/case-studies

Attached is a screenshot of the error message in the admin area and the stack trace was pasted into the original comment. If you need more specific code, let me know.

Cheers!

screen shot 2017-01-20 at 18 03 08

@nineteeneightyeight
Copy link
Author

Also the blueprint is as follows:

fields:
  header.taxonomy:
       type: taxonomy
       label: PLUGIN_ADMIN.TAXONOMY
       validate:
           type: array

Which, I believe (it's been a while since I've touched this code), when saved in the frontmatter of the case-studies child pages becomes:

taxonomy:
    category:
        - Retail

@rhukster
Copy link
Member

Ok, i was just looking at this order stuff on collection pages today. It currently only supports one level under 'header... let me see if I can address it.

@rhukster
Copy link
Member

Fixed in develop

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

3 participants