Problem/Motivation
I have a content type with a media entity field (documents bundle), displaying the rendered entity using the "Media Library" display format. This throws the following errors:
TypeError: Drupal\twig_tweak\TwigTweakExtension::withFilter(): Argument #1 ($build) must be of type array, null given, called in vendor/twig/twig/src/Environment.php(421) : eval()'d code on line 105 in Drupal\twig_tweak\TwigTweakExtension::withFilter() (line 601 of modules/contrib/twig_tweak/src/TwigTweakExtension.php).
TypeError: Drupal\twig_tweak\TwigTweakExtension::withFilter(): Return value must be of type array, null returned in Drupal\twig_tweak\TwigTweakExtension::withFilter() (line 610 of modules/contrib/twig_tweak/src/TwigTweakExtension.php).
The errors only occur with this display format, "Default" and custom display formats work fine.
Steps to reproduce
Install Drupal Media modules with the Documents media bundle (i.e. using the recipe provided by Drupal).
Add a media field for documents to any content type and configure it to use the "Media Library" display format.
Create some content and view.
Proposed resolution
Allow the filter function TwigTweakExtension::withFilter() to accept NULL for the $build parameter and handle it properly.
Issue fork twig_tweak-3550729
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
- 3550729-with-filter-null
changes, plain diff MR !95
- 3550729-with-filter-does
changes, plain diff MR !71
Comments
Comment #3
mvonfrie commentedMR71 works. The failing PHPUnit tests are unrelated and should be fixed in a separate issue.
Comment #4
mvonfrie commentedComment #5
anybodyShould go into 4.x @mvonfrie can you fix that?
Comment #6
rfranchini commentedMR !71 no longer applies to 4.x (it's out of scope and withFilter() is now private). Opening a fresh MR against 4.x that only makes the with filter accept a NULL build array (treated as an empty array), plus a test.
Comment #9
anybodyFix LGTM. @grevil please merge if you agree and this goes green.
Comment #11
anybodyComment #12
anybodyMerged!
Comment #14
rfranchini commentedHi @Anybody, sorry to bother you! If it's not a hassle, I'd really appreciate being credited for this small fix — my contribution record still shows empty for it. Thanks so much for reviewing and merging it! 🙏
Comment #15
grevil commented@rfranchini he accidentally forgot to adjust the contribution record entirely!
I just adjusted it accordingly. You should have the credit by now.