Problem/Motivation

I have a media reference field on a node that uses media images. When I try to use the field as a source in a pattern, I get the following error when viewing the node page.

The website encountered an unexpected error. Please try again later.
Error: Object of class Drupal\media\Entity\Media could not be converted to string in Drupal\ui_patterns_field_formatters\Plugin\Field\FieldFormatter\PatternFormatter->viewElements() (line 211 of modules/contrib/ui_patterns_field_formatters/src/Plugin/Field/FieldFormatter/PatternFormatter.php).
Drupal\ui_patterns_field_formatters\Plugin\Field\FieldFormatter\PatternFormatter->viewElements(Object, 'en') (Line: 89)
Drupal\Core\Field\FormatterBase->view(Object, 'en') (Line: 263)
Drupal\Core\Entity\Entity\EntityViewDisplay->buildMultiple(Array) (Line: 267)
Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay->buildMultiple(Array) (Line: 340)
Drupal\Core\Entity\EntityViewBuilder->buildComponents(Array, Array, Array, 'full') (Line: 24)
Drupal\node\NodeViewBuilder->buildComponents(Array, Array, Array, 'full') (Line: 282)
Drupal\Core\Entity\EntityViewBuilder->buildMultiple(Array) (Line: 239)
Drupal\Core\Entity\EntityViewBuilder->build(Array)
call_user_func_array(Array, Array) (Line: 101)
Drupal\Core\Render\Renderer->doTrustedCallback(Array, Array, 'Render #pre_render callbacks must be methods of a class that implements \Drupal\Core\Security\TrustedCallbackInterface or be an anonymous function. The callback was %s. See https://www.drupal.org/node/2966725', 'exception', 'Drupal\Core\Render\Element\RenderCallbackInterface') (Line: 781)
Drupal\Core\Render\Renderer->doCallback('#pre_render', Array, Array) (Line: 372)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 200)
Drupal\Core\Render\Renderer->render(Array, ) (Line: 241)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 573)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 242)
Drupal\Core\Render\MainContent\HtmlRenderer->prepare(Array, Object, Object) (Line: 132)
Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse(Array, Object, Object) (Line: 90)
Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object, 'kernel.view', Object)
call_user_func(Array, Object, 'kernel.view', Object) (Line: 142)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object, 'kernel.view') (Line: 163)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 80)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 52)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 706)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

Steps to reproduce

  1. Enable the UI pattern field formatters module and core media.
  2. Add a media reference field to a content type that loads media image items.
  3. In the node view display setting, select a pattern for the media reference field.
  4. Save the display mode form.
  5. Go to the node page and their should be a WSOD with the above error message.
CommentFileSizeAuthor
Screen Shot 2021-06-17 at 11.26.43 AM.png40.37 KBpcate

Comments

PCate created an issue. See original summary.

pdureau’s picture

Assigned: Unassigned » pdureau

Indeed, I may replace the call to th entity object by a call to its label base field.

pdureau’s picture

Status: Active » Needs work
duaelfr’s picture

Title: WSOD error when using pattern with core media reference field. » WSOD error when using pattern with core reference field.
Version: 8.x-1.2 » 8.x-1.x-dev
Assigned: pdureau » Unassigned

The error occurs when using the Pattern formatter on any entity reference field.

  • ccec5c7 committed on 8.x-1.x
    Issue #3219387 by DuaelFr, PCate: WSOD error when using pattern with...
duaelfr’s picture

Status: Needs work » Fixed

The Pattern formatter now use the entity label instead of throwing an error.
If you need the rendered entity, use the "Rendered entity, wrapped in a pattern" formatter instead.

Status: Fixed » Closed (fixed)

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