Error if the entity ID is empty in drupalField() when using drupal_field()

Created on 15 November 2021, over 3 years ago
Updated 11 July 2025, 1 day ago

Problem/Motivation

I got the next error

Argument 3 passed to Drupal\twig_tweak\TwigTweakExtension::drupalField() must be of the type string, null given, called in /vendor/twig/twig/src/Environment.php(418) : eval()'d code on line 42 in Drupal\twig_tweak\TwigTweakExtension::drupalField() (line 195 of modules/contrib/twig_tweak/src/TwigTweakExtension.php).

Steps to reproduce

I'm now quite sure when this happened. I was making module updates and core upgrade to 9. After the upgrade I tested the Webform and got the mentioned error. The Webform also uses AJAX and multistep.
I am using drupal_field() in a Webform and after the upgrade one of the fields that was prepopulated was indicated with no value.

Versions before and after update:

  • Core 8.9.19 -> 9.2.8
  • Webform 6.0.5 -> 6.1.0
  • Twig Tweak 2.9.0 -> 3.1.3

Proposed resolution

I tried to add some conditions to it, but it didn't work. The only thing that did, is attached in the patch.

Maybe the solution is not intended for this module, because I saw in another issue, where is mentioned, that it's up to developer to make sure that drupal_field() gets a correct entity ID. But in my case it was not working. If my solution is not accepted, maybe will help somebody in my situation.

Feature request
Status

Closed: works as designed

Version

3.1

Component

Code

Created by

🇸🇮Slovenia joco_sp

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.

Production build 0.71.5 2024