Problem/Motivation

The errormessage '@translator is not available. Make sure it is properly <a href=:configured>configured</a>.' needs a string for placeholder :configured (at the moment it is an url)

The error message for this is as follows:

TypeError: strpos(): Argument #1 ($haystack) must be of type string, Drupal\Core\Url given in strpos() (Zeile 358 in /app/web/core/lib/Drupal/Component/Utility/UrlHelper.php)
#0 /app/web/core/lib/Drupal/Component/Utility/UrlHelper.php(358): strpos(Object(Drupal\Core\Url), ':')
#1 /app/web/core/lib/Drupal/Component/Render/FormattableMarkup.php(213): Drupal\Component\Utility\UrlHelper::stripDangerousProtocols(Object(Drupal\Core\Url))
#2 /app/web/core/lib/Drupal/Core/StringTranslation/TranslatableMarkup.php(195): Drupal\Component\Render\FormattableMarkup::placeholderFormat('@translator ist...', Array)
#3 /app/web/core/lib/Drupal/Component/Utility/ToStringTrait.php(15): Drupal\Core\StringTranslation\TranslatableMarkup->render()
#4 /tmp/ag6ytatmq5eto/phpstorage/twig/c4a8cd5f804eb07f9889942d64455deeb2b9e071/twig/62bd6d0facc7a_details.html.twig_8_RaCBo9jpzHIapfj5lpk8Bdq/ehBh0LnkhKXAkZHN-oB2ERfK_I_JmPQ4GU4Mae8a7e8.php(76): Drupal\Core\StringTranslation\TranslatableMarkup->__toString()
#5 /app/vendor/twig/twig/src/Template.php(405): __TwigTemplate_553d331d443ef749fc9c1004f6a9bad27b1ad91af4ff0030cae5a2f26dad8ae9->doDisplay(Array, Array)
#6 /app/vendor/twig/twig/src/Template.php(378): Twig\Template->displayWithErrorHandling(Array, Array)
#7 /app/vendor/twig/twig/src/Template.php(390): Twig\Template->display(Array)
#8 /app/web/core/themes/engines/twig/twig.engine(55): Twig\Template->render(Array)
#9 /app/web/core/lib/Drupal/Core/Theme/ThemeManager.php(506): twig_render_template('core/themes/sev...', Array)
#10 /app/web/core/lib/Drupal/Core/Render/Renderer.php(478): Drupal\Core\Theme\ThemeManager->render('details', Array)
#11 /app/web/core/lib/Drupal/Core/Render/Renderer.php(435): Drupal\Core\Render\Renderer->doRender(Array)
#12 /app/web/core/lib/Drupal/Core/Render/Renderer.php(435): Drupal\Core\Render\Renderer->doRender(Array)
#13 /app/web/core/lib/Drupal/Core/Render/Renderer.php(201): Drupal\Core\Render\Renderer->doRender(Array, false)
#14 /app/web/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php(241): Drupal\Core\Render\Renderer->render(Array, false)
#15 /app/web/core/lib/Drupal/Core/Render/Renderer.php(564): Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}()
#16 /app/web/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php(242): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure))
#17 /app/web/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php(132): Drupal\Core\Render\MainContent\HtmlRenderer->prepare(Array, Object(Symfony\Component\HttpFoundation\Request), Object(Drupal\Core\Routing\CurrentRouteMatch))
#18 /app/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))
#19 [internal function]: Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object(Symfony\Component\HttpKernel\Event\ViewEvent), 'kernel.view', Object(Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher))
#20 /app/web/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php(142): call_user_func(Array, Object(Symfony\Component\HttpKernel\Event\ViewEvent), 'kernel.view', Object(Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher))
#21 /app/vendor/symfony/http-kernel/HttpKernel.php(163): Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object(Symfony\Component\HttpKernel\Event\ViewEvent), 'kernel.view')
#22 /app/vendor/symfony/http-kernel/HttpKernel.php(80): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1)
#23 /app/web/core/lib/Drupal/Core/StackMiddleware/Session.php(58): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#24 /app/web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#25 /app/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#26 /app/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#27 /app/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#28 /app/web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#29 /app/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#30 /app/web/core/lib/Drupal/Core/DrupalKernel.php(708): Stack\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#31 /app/web/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request))

Steps to reproduce

Add a the povider deepl under translation -> providers and leave the 'DeepL API authentication key'-field empty. Then try to request a translation of a content and you get the error message that is shown above.

Proposed resolution

It should be fixed when we convert the url to a string

At the class DeeplTranslator.php (line 97-100) you find this code:

return AvailableResult::no($this->t('@translator is not available. Make sure it is properly <a href=:configured>configured</a>.', [
      '@translator' => $translator->label(),
      ':configured' => $translator->toUrl(),
    ]));

but that should be the same that is on the translation module in file TestTranslator.php (on line 107 - 110)

return AvailableResult::no(t('@translator is not available. Make sure it is properly <a href=:configured>configured</a>.', [
        '@translator' => $translator->label(),
        ':configured' => $translator->toUrl()->toString(),
      ]));

(as you can see the ':configured' is set with the ->toString() method at the end.)d

Remaining tasks

add the ->toString() method (in file DeeplTranslator.php on line 99)

Comments

romina_ferrario created an issue. See original summary.

romina_ferrario’s picture

Issue summary: View changes
romina_ferrario’s picture

Issue summary: View changes
steffenr’s picture

@romina_ferrario hi - thanks for your finding.

Feel free to create a merge request to fix this issue.

Thanks,
SteffenR

steffenr’s picture

Assigned: Unassigned » steffenr

  • SteffenR committed c08b5d4 on 2.1.x
    #3293598:  convert url object to string to fix php error in...
steffenr’s picture

Assigned: steffenr » Unassigned
Status: Needs work » Fixed

  • SteffenR committed 784e0c7 on 2.1.x
    Revert "#3293598:  convert url object to string to fix php error in...
  • SteffenR committed ae1d8cb on 2.1.x
    Issue #3293598 by romina_ferrario, SteffenR: Error message needs string...

Status: Fixed » Closed (fixed)

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