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}.

Comments

mathew.oakes created an issue. See original summary.

mathew.oakes’s picture

yogeshmpawar’s picture

Status: Active » Needs review
krzysztof domański’s picture

StatusFileSize
new861 bytes
Error: Call to a member function getEntityTypeId() on null in Drupal\Core\Entity\EntityViewBuilder->getSingleFieldDisplay() (line 525 of 

The problem is that the first argument of the getSingleFieldDisplay() method must be \Drupal\Core\Entity\EntityInterface object. It can not be NULL.

/**
 * Gets an EntityViewDisplay for rendering an individual field.
 *
 * @param \Drupal\Core\Entity\EntityInterface $entity
 *   The entity.
 * @param string $field_name
 *   The field name.
 * @param string|array $display_options
 *   The display options passed to the viewField() method.
 *
 * @return \Drupal\Core\Entity\Display\EntityViewDisplayInterface
 */
protected function getSingleFieldDisplay($entity, $field_name, $display_options) {
tim.plunkett’s picture

Version: 8.7.x-dev » 8.8.x-dev
Issue tags: +Blocks-Layouts, +Needs tests, +Needs steps to reproduce

This 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

tanmayk’s picture

We 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.

anybody’s picture

Status: Needs review » Closed (duplicate)

This 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!

anybody’s picture

Status: Closed (duplicate) » Active

I 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?

anybody’s picture

@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.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

anybody’s picture

Status: Active » Closed (works as designed)

With 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.

jhedstrom’s picture

Status: Closed (works as designed) » Closed (duplicate)

Should be closed as a duplicate rather than works as designed :)