HtmlEscapedText object to string conversion error

Created on 12 May 2017, about 8 years ago
Updated 21 March 2023, over 2 years 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

Postponed: needs info

Version

10.1 ✨

Component
RenderΒ  β†’

Last updated 1 day 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 over 1 year 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.

  • πŸ‡¬πŸ‡·Greece dimitriskr

    I got a similar error on my project. I'm trying to find clean reproducible steps. For now, I got it when I tried to render a message entity that had an entity reference field for a view and I used a token [message:field_view_ref:entity:label] in the message's text and rendered it programmatically

    Error: Object of class Drupal\views\Entity\View could not be converted to string in Drupal\Component\Render\HtmlEscapedText->__construct() (line 31 of core/lib/Drupal/Component/Render/HtmlEscapedText.php).

        $view_builder = \Drupal::entityTypeManager()->getViewBuilder('message');
        $pre_render = $view_builder->view($message_entity, 'default');
    
Production build 0.71.5 2024