This started occuring without an obvious trigger. Error would prevent layout_builder UI from loading. Attached patch enables continued use of layout builder interface, however am unclear about what is really causing this problem.
Error: Call to a member function getEntityTypeId() on null in Drupal\Core\Entity\EntityViewBuilder->getSingleFieldDisplay() (line 525 of /var/www/html/drupal/web/core/lib/Drupal/Core/Entity/EntityViewBuilder.php) #0 /var/www/html/drupal/web/core/lib/Drupal/Core/Entity/EntityViewBuilder.php(461): Drupal\Core\Entity\EntityViewBuilder->getSingleFieldDisplay(NULL, 'field_pilot_ima...', Array) #1 /var/www/html/drupal/web/core/lib/Drupal/Core/Field/FieldItemList.php(243): Drupal\Core\Entity\EntityViewBuilder->viewField(Object(Drupal\file\Plugin\Field\FieldType\FileFieldItemList), Array) #2 /var/www/html/drupal/web/core/modules/layout_builder/src/Plugin/Block/FieldBlock.php(161): Drupal\Core\Field\FieldItemList->view(Array) #3 /var/www/html/drupal/web/core/modules/layout_builder/src/EventSubscriber/BlockComponentRenderArray.php(104): Drupal\layout_builder\Plugin\Block\FieldBlock->build() #4 [internal function]: Drupal\layout_builder\EventSubscriber\BlockComponentRenderArray->onBuildRender(Object(Drupal\layout_builder\Event\SectionComponentBuildRenderArrayEvent), 'section_compone...', Object(Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher)) #5 /var/www/html/drupal/web/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php(111): call_user_func(Array, Object(Drupal\layout_builder\Event\SectionComponentBuildRenderArrayEvent), 'section_compone...', Object(Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher)) #6 /var/www/html/drupal/web/core/modules/layout_builder/src/SectionComponent.php(90): Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch('section_compone...', Object(Drupal\layout_builder\Event\SectionComponentBuildRenderArrayEvent)) #7 /var/www/html/drupal/web/core/modules/layout_builder/src/Section.php(86): Drupal\layout_builder\SectionComponent->toRenderArray(Array, true) #8 /var/www/html/drupal/web/core/modules/layout_builder/src/Element/LayoutBuilder.php(247): Drupal\layout_builder\Section->toRenderArray(Array, true) #9 /var/www/html/drupal/web/core/modules/layout_builder/src/Element/LayoutBuilder.php(123): Drupal\layout_builder\Element\LayoutBuilder->buildAdministrativeSection(Object(Drupal\layout_builder\Plugin\SectionStorage\DefaultsSectionStorage), 0) #10 /var/www/html/drupal/web/core/modules/layout_builder/src/Element/LayoutBuilder.php(97): Drupal\layout_builder\Element\LayoutBuilder->layout(Object(Drupal\layout_builder\Plugin\SectionStorage\DefaultsSectionStorage)) #11 [internal function]: Drupal\layout_builder\Element\LayoutBuilder->preRender(Array) #12 /var/www/html/drupal/web/core/lib/Drupal/Core/Render/Renderer.php(378): call_user_func(Array, Array) #13 /var/www/html/drupal/web/core/lib/Drupal/Core/Render/Renderer.php(450): Drupal\Core\Render\Renderer->doRender(Array) #14 /var/www/html/drupal/web/core/lib/Drupal/Core/Render/Renderer.php(195): Drupal\Core\Render\Renderer->doRender(Array, false) #15 /var/www/html/drupal/web/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php(226): Drupal\Core\Render\Renderer->render(Array, false) #16 /var/www/html/drupal/web/core/lib/Drupal/Core/Render/Renderer.php(582): Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() #17 /var/www/html/drupal/web/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php(227): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure)) #18 /var/www/html/drupal/web/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php(117): Drupal\Core\Render\MainContent\HtmlRenderer->prepare(Array, Object(Symfony\Component\HttpFoundation\Request), Object(Drupal\Core\Routing\CurrentRouteMatch)) #19 /var/www/html/drupal/web/core/lib/Drupal/Core/EventSubscriber/MainContentViewSubscriber.php(90): Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse(Array, Object(Symfony\Component\HttpFoundation\Request), Object(Drupal\Core\Routing\CurrentRouteMatch)) #20 [internal function]: Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object(Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent), 'kernel.view', Object(Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher)) #21 /var/www/html/drupal/web/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php(111): call_user_func(Array, Object(Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent), 'kernel.view', Object(Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher)) #22 /var/www/html/drupal/vendor/symfony/http-kernel/HttpKernel.php(156): Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch('kernel.view', Object(Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent)) #23 /var/www/html/drupal/vendor/symfony/http-kernel/HttpKernel.php(68): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1) #24 /var/www/html/drupal/web/core/lib/Drupal/Core/StackMiddleware/Session.php(57): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #25 /var/www/html/drupal/web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(47): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #26 /var/www/html/drupal/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #27 /var/www/html/drupal/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass(Object(Symfony\Component\HttpFoundation\Request), 1, true) #28 /var/www/html/drupal/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(47): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #29 /var/www/html/drupal/web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(52): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #30 /var/www/html/drupal/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #31 /var/www/html/drupal/web/core/lib/Drupal/Core/DrupalKernel.php(693): Stack\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #32 /var/www/html/drupal/web/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request)) #33 {main}.
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | 3063839-4.patch | 861 bytes | krzysztof domański |
| #2 | drupal-layout_builder_error-3063839-8.7.x_0.patch | 1.24 KB | mathew.oakes |
Comments
Comment #2
mathew.oakes commentedComment #3
yogeshmpawarComment #4
krzysztof domańskiThe problem is that the first argument of the
getSingleFieldDisplay()method must be\Drupal\Core\Entity\EntityInterfaceobject. It can not be NULL.Comment #5
tim.plunkettThis issue needs clear steps to reproduce, so that automated tests can be written. Leaving in the LB component for now, but all the patches so far have been against the entity system itself
Comment #6
tanmaykWe should find a root cause of the problem here & see why we are getting NULL in there.
Also yes, we need steps to reproduce the issue.
Comment #7
anybodyThis seems to be a clear duplicate of #3049332: Fix Log error + visual warning for missing or broken block which contains a better patch with logging but should also look for the root cause, as @tim.plunkett said in #5.Sorry I was wrong, that issue might be related or is similar but not duplicate!
Comment #8
anybodyI have to correct my comment from #7 - the issue #3049332 is similar, perhaps even has the same cause, but it is not the same error. As written in #6 we should determine the root cause and write tests for expected behaviour.
The patch from #3049332: Fix Log error + visual warning for missing or broken block is a good example, I think, how we could mitigate the hard error effect for broken / existing sites by using the logger for now.
I'd suggest to improve the hotfix from #4 by logging like in the other patch and provide that as intermediate patch until we found the true reason?
Comment #9
anybody@all the others in this discussion: Are you also using the patch from comment #62 in #2955392: EntityViewBuilder::viewField() does not respect entity current language when used with an entity reference field?
For me it seems as if the patch needs work and causes this problem. If you're all using this patch from that issue, we should continue there and close this issue. If not, please tell us about your Drupal Version and patches.
Comment #10
anybodyComment #11
anybodyComment #13
anybodyWith patch #91 from #2955392: EntityViewBuilder::viewField() does not respect entity current language when used with an entity reference field instead of an older one, this error disappears for me. So I guess this was caused by a patch from that issue.
Comment #14
anybodyComment #15
jhedstromShould be closed as a duplicate rather than works as designed :)