Under PHP 8.1 in Drupal 9.4 I have a Table Field on a content type that has its display managed by Layout Builder. The Table Field field has been placed in the layout and shows up using the "Tabular View" formatter.

When I go to Layout Builder I now see the following warning:

Warning: Undefined array key "caption" in Drupal\tablefield\Plugin\Field\FieldFormatter\TablefieldFormatter->viewElements() (line 150 of modules/contrib/tablefield/src/Plugin/Field/FieldFormatter/TablefieldFormatter.php).
Drupal\tablefield\Plugin\Field\FieldFormatter\TablefieldFormatter->viewElements(Object, 'en') (Line: 89)
Drupal\Core\Field\FormatterBase->view(Object, 'en') (Line: 265)
Drupal\Core\Entity\Entity\EntityViewDisplay->buildMultiple(Array) (Line: 266)
Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay->buildMultiple(Array) (Line: 223)
Drupal\Core\Entity\Entity\EntityViewDisplay->build(Object) (Line: 461)
Drupal\Core\Entity\EntityViewBuilder->viewField(Object, Array) (Line: 243)
Drupal\Core\Field\FieldItemList->view(Array) (Line: 162)
Drupal\layout_builder\Plugin\Block\FieldBlock->build() (Line: 106)

Just checking isset($tabledata['caption']) seems like all we need here.

Issue fork tablefield-3326647

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

floydm created an issue. See original summary.

floydm’s picture

StatusFileSize
new727 bytes
vrancje’s picture

Patch works for me, thank you!

j.’s picture

Patch applied cleanly on php8.1 drupal 9.5.7. Error is gone for me too. Thank you!

samitk’s picture

Assigned: Unassigned » samitk
Status: Active » Needs work
samitk’s picture

StatusFileSize
new697 bytes
new621 bytes

#2 patch seems good, But i guess we should use Null Coalescing Operator instead of Ternary Operator.

interdiff with #2

samitk’s picture

Assigned: samitk » Unassigned
Status: Needs work » Needs review
liam morland’s picture

Version: 8.x-2.x-dev » 3.0.x-dev
Status: Needs review » Needs work
Issue tags: +Needs reroll

Please use an issue fork and merge request.

arunsahijpal’s picture

Assigned: Unassigned » arunsahijpal

Working on it.

arunsahijpal’s picture

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

Hi @liam-morland,
I have reproduced the issue on my local and got the same warning,but after applying the patch the warning disappears.
So making a MR for it.
pls check.

Thanks
Arun.

liam morland’s picture

Status: Needs review » Needs work

Thanks for the patch. This needs to be rebased onto the current 3.0.x.

arunsahijpal’s picture

Status: Needs work » Needs review
liam morland’s picture

Status: Needs review » Needs work

Please make the merge request target 3.0.x.

arunsahijpal’s picture

Status: Needs work » Needs review

@liam-morland,
I've changed the targeted branch.

liam morland’s picture

Status: Needs review » Needs work

The merge request has a bunch of other commits in it. It needs to be rebased so it is only the commits for this issue.

liam morland’s picture

Status: Needs work » Fixed
Issue tags: -Needs reroll

Status: Fixed » Closed (fixed)

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