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.
| Comment | File | Size | Author |
|---|---|---|---|
| #6 | interdiff_2-5.txt | 621 bytes | samitk |
| #6 | 3326647-5.patch | 697 bytes | samitk |
| #2 | tablefield-caption-warning-3326647-2.patch | 727 bytes | floydm |
Issue fork tablefield-3326647
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
Comment #2
floydm commentedComment #3
vrancjePatch works for me, thank you!
Comment #4
j. commentedPatch applied cleanly on php8.1 drupal 9.5.7. Error is gone for me too. Thank you!
Comment #5
samitk commentedComment #6
samitk commented#2 patch seems good, But i guess we should use Null Coalescing Operator instead of Ternary Operator.
interdiff with #2
Comment #7
samitk commentedComment #8
liam morlandPlease use an issue fork and merge request.
Comment #9
arunsahijpal commentedWorking on it.
Comment #11
arunsahijpal commentedHi @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.
Comment #12
liam morlandThanks for the patch. This needs to be rebased onto the current 3.0.x.
Comment #13
arunsahijpal commentedComment #14
liam morlandPlease make the merge request target 3.0.x.
Comment #15
arunsahijpal commented@liam-morland,
I've changed the targeted branch.
Comment #16
liam morlandThe merge request has a bunch of other commits in it. It needs to be rebased so it is only the commits for this issue.
Comment #19
liam morland