Warning: Undefined array key 0 in ParagraphsTableFormatter.php on line 474

Created on 18 August 2025, about 1 month ago

Problem/Motivation

Warning: Undefined array key 0 in /web/modules/contrib/paragraphs_table/src/Plugin/Field/FieldFormatter/ParagraphsTableFormatter.php on line 474

Warning: Trying to access array offset on null in /web/modules/contrib/paragraphs_table/src/Plugin/Field/FieldFormatter/ParagraphsTableFormatter.php on line 474

Seems to happen, if the paragraphs field is empty

Steps to reproduce

  1. Show Notices & warnings in php
  2. Open a node with paragraphs_table formatter and a paragraphs reference field that has no entries
  3. See the notices / warnings

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Active

Version

2.0

Component

Code

Created by

🇩🇪Germany Anybody Porta Westfalica

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @Anybody
  • Merge request !18Fix $type variable → (Merged) created by Anybody
  • Pipeline finished with Success
    about 1 month ago
    Total: 147s
    #575538
  • 🇩🇪Germany Anybody Porta Westfalica

    Okay looks like this isn't just the case for empty paragraphs. It seems like a logical bug, maybe regression.

    In these lines:

        $target_bundles = array_keys($handler["target_bundles"]);
        if (!empty($handler['negate'])) {
          $bundles = $this->entityTypeBundleInfo->getBundleInfo('paragraph');
          $target_bundles = array_keys(array_diff_key($bundles, $handler['target_bundles']));
        }
        $type = key($target_bundles);
    

    array_keys() already returns the keys as array values. So we need to get the value to get the type machine name:

    $type = reset($target_bundles);
    

    Otherwise, $type is the numeric key ($type=0) and the following lines break.

    The MR fixes that, please review.

  • 🇩🇪Germany Anybody Porta Westfalica

    Seems this was once again merged without credit from the maintainer.

Production build 0.71.5 2024