HtmlEscapedText object to string conversion error

Created on 12 May 2017, about 7 years ago
Updated 22 January 2024, 5 months ago

I have got this error:

The website encountered an unexpected error. Please try again later.
Recoverable fatal error: Object of class Drupal\Core\Url could not be converted to string in Drupal\Component\Render\HtmlEscapedText->__construct() (line 41 of core/lib/Drupal/Component/Render/HtmlEscapedText.php).

Drupal\Component\Render\HtmlEscapedText->__construct(Object) (Line: 204)
Drupal\Core\Utility\Token->replace('[node:field_jissue_cover:entity:url]', Array, Array) (Line: 40)
Drupal\metatag\MetatagToken->replace('[node:field_jissue_cover:entity:url]', Array, Array) (Line: 293)
Drupal\metatag\MetatagManager->generateElements(Array, Object) (Line: 321)
metatag_get_tags_from_route() (Line: 143)
metatag_entity_view_alter(Array, Object, Object) (Line: 501)
Drupal\Core\Extension\ModuleHandler->alter(Array, Array, Object, Object) (Line: 285)
Drupal\Core\Entity\EntityViewBuilder->buildMultiple(Array) (Line: 220)
Drupal\Core\Entity\EntityViewBuilder->build(Array)
call_user_func(Array, Array) (Line: 376)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 195)
Drupal\Core\Render\Renderer->render(Array, ) (Line: 226)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 574)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 227)
Drupal\Core\Render\MainContent\HtmlRenderer->prepare(Array, Object, Object) (Line: 117)
Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse(Array, Object, Object) (Line: 90)
Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object, 'kernel.view', Object) (Line: 111)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch('kernel.view', Object) (Line: 149)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 64)
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: 99)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 78)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 50)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 656)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
πŸ› Bug report
Status

Closed: outdated

Version

11.0 πŸ”₯

Component
RenderΒ  β†’

Last updated 2 days ago

Created by

πŸ‡­πŸ‡ΊHungary brtamas

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ

    I've tried to re-create this bug according to the information in the issue summary. I created an entity reference field and used it as a token replacement in a text field that supported tokens - it looked something like [node:field_test:entity:url] - this works absolutely fine. The token module is correctly calling toString() on the URL object to get the token value.

    We need more information with steps to reproduce. It feels that the real problem here is in the token provider not calling ->toString() on URL objects and fixing this in HtmlEscapedText is in the wrong place.

  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ

    I also tested this with a link field and [node:field_link:uri] works as expected without error.

  • Status changed to Closed: outdated 5 months ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Since there hasn't been a follow up going to close out as outdated for now. If still a valid bug in D10 please update issue summary with steps to reproduce.

Production build 0.69.0 2024