Exception: Object of type Drupal\media\Entity\MediaType cannot be printed.

Created on 12 July 2024, about 2 months ago
Updated 20 July 2024, about 2 months ago

Problem/Motivation

Devel tokens tab throws an exception:

The website encountered an unexpected error. Try again later.

Exception: Object of type Drupal\media\Entity\MediaType cannot be printed. in Drupal\Core\Template\TwigExtension->escapeFilter() (line 450 of core/lib/Drupal/Core/Template/TwigExtension.php).
__TwigTemplate_03a47ca46b943d43e12ecca59275f53d->doDisplay(Array, Array) (Line: 394)
Twig\Template->displayWithErrorHandling(Array, Array) (Line: 367)
Twig\Template->display(Array) (Line: 379)
Twig\Template->render(Array) (Line: 38)
Twig\TemplateWrapper->render(Array) (Line: 39)
twig_render_template('themes/contrib/gin/templates/dataset/table.html.twig', Array) (Line: 348)
Drupal\Core\Theme\ThemeManager->render('table', Array) (Line: 480)
Drupal\Core\Render\Renderer->doRender(Array) (Line: 493)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 240)
Drupal\Core\Render\Renderer->render(Array, ) (Line: 238)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 627)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 231)
Drupal\Core\Render\MainContent\HtmlRenderer->prepare(Array, Object, Object) (Line: 128)
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: 111)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object, 'kernel.view') (Line: 186)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 76)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 28)
Drupal\Core\StackMiddleware\ContentLength->handle(Object, 1, 1) (Line: 32)
Drupal\big_pipe\StackMiddleware\ContentLength->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: 53)
Asm89\Stack\Cors->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 36)
Drupal\Core\StackMiddleware\AjaxPageState->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object, 1, 1) (Line: 704)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

I have traced this backwards to the following token that is causing the issue and it appears to be a missing toString() or _toString() method on the Drupal\media\Entity\MediaType entity.

The token in question is [group:field_image:entity:bundle:entity]. Also tried nodes and the same error is thrown for [node:field_image:entity:bundle:entity].

I'm opening this on the Core issue queue because I don't think any of the modules listed below are the culprit. But if I'm wrong, feel free to re-assign to the appropriate queue.

Steps to reproduce

There are a lot of moving parts, but here is what is required:

  • Core (v10.2.7)
  • Group module (v2.2.2)
  • Token module (v8.x-1.14)
  • Devel module (v5.2.1)
  • Gin theme (v8.x-3.0-rc13)

Configuration:

  • Create a group type
  • Create an Image media type (if one does not exist)
  • Add media entity reference field to the group type
  • Create a group using the newly created type
  • Visit the Devel tab and the Token sub-tab

Proposed resolution

I've created a local patch for the site to add a benign toString() method to the MediaType entity. I DO NOT think this is the proper fix, but it works for my purposes.

Remaining tasks

N/A

User interface changes

N/A

API changes

N/A

Data model changes

N/A

Release notes snippet

N/A

πŸ› Bug report
Status

Postponed: needs info

Version

11.0 πŸ”₯

Component
MediaΒ  β†’

Last updated less than a minute ago

Created by

πŸ‡¨πŸ‡¦Canada slydevil Halifax

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

Comments & Activities

Production build 0.71.5 2024