TypeError: Argument 1 passed to Drupal\formatter_field\Plugin\Field\FieldFormatter\FromFieldFormatter::getFormatter()

Created on 25 January 2022, almost 3 years ago
Updated 5 December 2023, about 1 year ago

Problem/Motivation

For some case I got the error.

TypeError: Argument 1 passed to Drupal\formatter_field\Plugin\Field\FieldFormatter\FromFieldFormatter::getFormatter() must implement interface Drupal\Core\Field\FieldItemListInterface, null given, called in /app/web/modules/contrib/formatter_field/src/Plugin/Field/FieldFormatter/FromFieldFormatter.php on line 89 in Drupal\formatter_field\Plugin\Field\FieldFormatter\FromFieldFormatter->getFormatter() (line 113 of /app/web/modules/contrib/formatter_field/src/Plugin/Field/FieldFormatter/FromFieldFormatter.php)

It happens due grouping entites by bundle here.

Proposed resolution

`$entities_items` array may have no [0] item. I propose to get first item without [0] calling.

🐛 Bug report
Status

RTBC

Version

2.0

Component

Code

Created by

🇷🇺Russia validoll Ekaterinburg

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.

  • Status changed to RTBC about 1 year ago
  • 🇨🇦Canada man-1982

    Test Environment:

    Drupal version: 10.1.6
    DB driver: MySQL
    PHP OS: Linux
    PHP version: 8.1.25

    Results:

    The patch successfully resolved the issue described. All works good.
    Suggested @JurriaanRoelofs to add patch to main branch.
    thanks

  • Status changed to Needs review about 1 year ago
  • 🇨🇦Canada man-1982

    I noticed an issue: when attempting to edit or add a field in the "Manage fields" section, I consistently encountered an error. The error message displayed was:

    The website encountered an unexpected error. Please try again later.
    
    TypeError: array_intersect_key(): Argument #1 ($array) must be of type array, bool given in array_intersect_key() (line 158 of core/lib/Drupal/Core/Field/FormatterPluginManager.php).

    To resolve this issue, I applied a patch which successfully addressed the problem.

    My patch extends the patch by @validoll.
    Thanks

  • 🇦🇺Australia 44sunsets

    Can confirm the updated patch in #7 is working well, thank you.

  • Status changed to RTBC about 1 year ago
Production build 0.71.5 2024