Unable to create a node containing a union field, getting value should not be null error

Created on 21 April 2024, over 1 year ago

Problem/Motivation

When i try to create a node with the most basic union field with just a single plain text field on 10.2.5. i get the following error:

The website encountered an unexpected error. Try again later.

Error: Call to a member function build() on null in Drupal\field_union\Plugin\Field\FieldFormatter\FieldUnionFormatter->viewElements() (line 60 of modules/custom/field_union/src/Plugin/Field/FieldFormatter/FieldUnionFormatter.php).
Drupal\Core\Field\FormatterBase->view() (Line: 268)
Drupal\Core\Entity\Entity\EntityViewDisplay->buildMultiple() (Line: 339)
Drupal\Core\Entity\EntityViewBuilder->buildComponents() (Line: 24)
Drupal\node\NodeViewBuilder->buildComponents() (Line: 281)
Drupal\Core\Entity\EntityViewBuilder->buildMultiple() (Line: 238)
Drupal\Core\Entity\EntityViewBuilder->build()
call_user_func_array() (Line: 111)
Drupal\Core\Render\Renderer->doTrustedCallback() (Line: 859)
Drupal\Core\Render\Renderer->doCallback() (Line: 421)
Drupal\Core\Render\Renderer->doRender() (Line: 240)
Drupal\Core\Render\Renderer->render() (Line: 238)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 627)
Drupal\Core\Render\Renderer->executeInRenderContext() (Line: 231)
Drupal\Core\Render\MainContent\HtmlRenderer->prepare() (Line: 128)
Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse() (Line: 90)
Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray()
call_user_func() (Line: 111)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch() (Line: 186)
Symfony\Component\HttpKernel\HttpKernel->handleRaw() (Line: 76)
Symfony\Component\HttpKernel\HttpKernel->handle() (Line: 58)
Drupal\Core\StackMiddleware\Session->handle() (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle() (Line: 28)
Drupal\Core\StackMiddleware\ContentLength->handle() (Line: 32)
Drupal\big_pipe\StackMiddleware\ContentLength->handle() (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass() (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle() (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle() (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle() (Line: 36)
Drupal\Core\StackMiddleware\AjaxPageState->handle() (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle() (Line: 704)
Drupal\Core\DrupalKernel->handle() (Line: 19)

while on 11.x-dev i get an admin error message This value should not be null. and no WSOD and the plain text field of the union field outlined in red. both instances are running on DDEV with php 8.3

Steps to reproduce

  1. create /web/modules/custom/field_union
  2. git clone git@git.drupal.org:issue/field_union-3011353.git .
  3. git checkout field_union-3011353
  4. ddev drush en field_union
  5. on /admin/structure/field-union/add create a field union called myunion and set the initial field to text plain
  6. on admin/structure/field-union/manage/myunion/form-display enable the plain text field
  7. on admin/structure/field-union/manage/myunion/display enable the plain text field as well
  8. create a content type called test and remove its initial body field
  9. create a new field, choose the field union and the option myunion
  10. go to /node/add/test and enter text in both textfields

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Active

Component

Code

Created by

🇩🇪Germany rkoller Nürnberg, Germany

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

Comments & Activities

Production build 0.71.5 2024