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

Command icon 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:

Comments

mvonfrie created an issue. See original summary.

mvonfrie’s picture

Assigned: mvonfrie » Unassigned

MR71 works. The failing PHPUnit tests are unrelated and should be fixed in a separate issue.

There were 3 errors:
1) Drupal\Tests\twig_tweak\Functional\TwigTweakTest::testOutput
Drupal\Core\Config\UnmetDependenciesException: Configuration objects provided by twig_tweak_test have unmet dependencies: field.field.node.page.body (field.storage.node.body)
2) Drupal\Tests\twig_tweak\Kernel\UriExtractorTest::testUriExtractor
Exception: Exception when installing config for module twig_tweak_test, message was: Attempted to create, modify or delete an instance of field with name body on entity type node when the field storage does not exist.
3) Drupal\Tests\twig_tweak\Kernel\UrlExtractorTest::testUrlExtractor
Exception: Exception when installing config for module twig_tweak_test, message was: Attempted to create, modify or delete an instance of field with name body on entity type node when the field storage does not exist.
--
There was 1 failure:
1) Drupal\Tests\twig_tweak\Kernel\EntityViewBuilderTest::testEntityViewBuilder
Failed asserting that two strings are identical.

mvonfrie’s picture

Status: Active » Needs review
anybody’s picture

Version: 3.4.0 » 4.x-dev
Status: Needs review » Needs work

Should go into 4.x @mvonfrie can you fix that?

rfranchini’s picture

MR !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.

anybody changed the visibility of the branch 3550729-with-filter-does to hidden.

anybody’s picture

Assigned: Unassigned » grevil
Status: Needs work » Needs review

Fix LGTM. @grevil please merge if you agree and this goes green.

  • anybody committed 512f0b7b on 4.x authored by rfranchini
    Issue #3550729: Fix TypeError in 'with' filter when the build array is...
anybody’s picture

Assigned: grevil » Unassigned
Status: Needs review » Reviewed & tested by the community
anybody’s picture

Status: Reviewed & tested by the community » Fixed

Merged!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

rfranchini’s picture

Hi @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! 🙏

grevil’s picture

@rfranchini he accidentally forgot to adjust the contribution record entirely!

I just adjusted it accordingly. You should have the credit by now.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.