Twig failed to render submission entry (Drupal\Core\Language) and throw exception

Created on 22 December 2018, almost 6 years ago
Updated 19 July 2024, 4 months ago

Tested with simple webform "contact" example on "multi-lingual" site
Drupal composer built v. 8.6.3
Webform composer built v8.x-5.0-rc31

Displaying the submission on /admin/structure/webform/manage/contact/submission/1 throw the Exception
Exception: Object of type Drupal\Core\Language\Language cannot be printed. in Drupal\Core\Template\TwigExtension->escapeFilter() (line 465 of /web/core/lib/Drupal/Core/Template/TwigExtension.php).

On submission, the submission entry is auto-added with Drupal\Core\Language\Language

When I intercept the exception throwing of /web/core/lib/Drupal/Core/Template/TwigExtension.php on line 465 by...

465: var_export($args);exit;
466: throw new \Exception('Object of type ' . get_class($arg) . ' cannot be printed.');

It shows...

Language: Drupal\Core\Language\Language::__set_state(array( 'name' => 'Thai', 'id' => 'th', 'direction' => 'ltr', 'weight' => -10, 'locked' => false, ))

The submission line is shown in /admin/structure/webform/manage/contact/results/submissions as attached picture

🐛 Bug report
Status

Closed: won't fix

Version

5.0

Component

Code

Created by

🇹🇭Thailand vorapoap

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇮🇳India vikas500 Pune

    Modify the code as needed to correctly handle the Language object in twig file. Remember, you should access properties or methods of the Language object (like getId() for the language code) instead of trying to print the object directly.
    Error Code:- <span class="icpdlogo"><img src="{{ base_path ~ directory }}/images/icpd-30-logoinverted-{{ language }}.png" alt="ICPD"></span>
    Correct Code:- <span class="icpdlogo"><img src="{{ base_path ~ directory }}/images/icpd-30-logoinverted-{{ language.getId() }}.png" alt="ICPD"></span>

    Thank You!

Production build 0.71.5 2024