The following error occurs:

( ! ) Fatal error: Uncaught TypeError: Argument 1 passed to Drupal\Core\Cache\CacheableMetadata::createFromRenderArray() must be of the type array, null given, called in /web/modules/contrib/block_field/src/Plugin/Field/FieldFormatter/BlockFieldLabelFormatter.php on line 40 and defined in /web/core/lib/Drupal/Core/Cache/CacheableMetadata.php on line 149

In BlockFieldLabelFormatter its stated:

CacheableMetadata::createFromRenderArray($elements[$delta]['content'])

But the element's render array is:

      $elements[$delta] = [
        '#markup' => $block_instance->label(),
      ];

This merge statement looks to be a mistake.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

icondigital created an issue. See original summary.

ieguskiza’s picture

Hi, I added some tests to verify the issue. I attach a patch with only the test so it fails an another with the solution.

ieguskiza’s picture

I noticed that my first proposal has a hard dependency on versions of Drupal higher than 8.8. I attach another patch that is compatible with previous releases since I'm not sure what the appropriate approach is here.

Chewie’s picture

Status: Active » Needs review

Patch looks good for me.

sardara’s picture

  1. +++ b/tests/src/Functional/BlockFieldTest.php
    @@ -156,6 +156,19 @@ class BlockFieldTest extends BrowserTestBase {
    +    // Use the Block Field Label formatter for the block_field_test display.
    

    Isn't "block_field_test" the bundle name?

  2. +++ b/tests/src/Functional/BlockFieldTest.php
    @@ -156,6 +156,19 @@ class BlockFieldTest extends BrowserTestBase {
    +
    

    Let's put just a single empty line.

For the rest it looks good!

sardara’s picture

Status: Needs review » Needs work
ieguskiza’s picture

Hi @sardara, here are the patches with all the changes you proposed. I also added an interdiff for all of them.

ieguskiza’s picture

Status: Needs work » Needs review
sardara’s picture

Status: Needs review » Reviewed & tested by the community

Looks good! Moving to RTBC.

mpp’s picture

Priority: Major » Critical

This is causing a fatal error without a workaround, setting to critical.

RTBC++

mpp’s picture

Issue summary: View changes

Adding the complete error message for people to find this issue more easily.

( ! ) Fatal error: Uncaught TypeError: Argument 1 passed to Drupal\Core\Cache\CacheableMetadata::createFromRenderArray() must be of the type array, null given, called in /web/modules/contrib/block_field/src/Plugin/Field/FieldFormatter/BlockFieldLabelFormatter.php on line 40 and defined in /web/core/lib/Drupal/Core/Cache/CacheableMetadata.php on line 149
tim-diels’s picture

Status: Reviewed & tested by the community » Needs work
  1. +++ b/tests/src/Functional/BlockFieldTest.php
    @@ -156,6 +156,18 @@ class BlockFieldTest extends BrowserTestBase {
    +    // Use the Block Field Label formatter for the field_block_field_test display.
    

    phpcs: Line exceeds 80 characters; contains 82 characters

  2. +++ b/tests/src/Functional/BlockFieldTest.php
    @@ -156,6 +156,18 @@ class BlockFieldTest extends BrowserTestBase {
    +    entity_get_display('node', 'block_field_test', 'default')
    

    @deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use EntityDisplayRepositoryInterface::getViewDisplay() instead.

This patch needs a re-roll for Drupal 8.8+

sardara’s picture

@deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use EntityDisplayRepositoryInterface::getViewDisplay() instead.

It's present from 8.8, but not in 8.7. This module still reports compatibility with ^8.7.7, we shouldn't drop it for a test. Let's change the code to make it work and support 8.7 and 9.0.

tim-diels’s picture

Patch and interdiff provided

e.ryan.schmidt@gmail.com’s picture

Just tested the patch in #15 and it works great for me. Thanks!

paulocs’s picture

Status: Needs work » Needs review

Moving to needs review so tests can be added.

  • Berdir committed dd40c4b on 8.x-1.x authored by tim-diels
    Issue #3068281 by tim-diels: BlockFieldLabelFormatter CacheableMetadata...
Berdir’s picture

Status: Needs review » Fixed

Looks good to me and has a test. Committed.

Berdir’s picture

Status: Fixed » Closed (fixed)

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