TypeError: strpos(): Argument #1 ($haystack) must be of type string, Drupal\Core\Url given in strpos()

Created on 2 August 2023, over 1 year ago
Updated 18 September 2024, 5 months ago

Problem/Motivation

TypeError: strpos(): Argument #1 ($haystack) must be of type string, Drupal\Core\Url given in strpos() (line 358 of /var/www/html/web/core/lib/Drupal/Component/Utility/UrlHelper.php)
#0 /var/www/html/web/core/lib/Drupal/Component/Utility/UrlHelper.php(358): strpos(Object(Drupal\Core\Url), ':')
#1 /var/www/html/web/core/lib/Drupal/Component/Render/FormattableMarkup.php(221): Drupal\Component\Utility\UrlHelper::stripDangerousProtocols(Object(Drupal\Core\Url))
#2 /var/www/html/web/core/lib/Drupal/Core/StringTranslation/TranslatableMarkup.php(195): Drupal\Component\Render\FormattableMarkup::placeholderFormat('@translator is ...', Array)
#3 /var/www/html/web/core/lib/Drupal/Component/Utility/ToStringTrait.php(15): Drupal\Core\StringTranslation\TranslatableMarkup->render()
#4 /var/www/html/web/core/lib/Drupal/Core/Messenger/Messenger.php(54): Drupal\Core\StringTranslation\TranslatableMarkup->__toString()
#5 /var/www/html/web/core/lib/Drupal/Core/Form/FormErrorHandler.php(45): Drupal\Core\Messenger\Messenger->addMessage(Object(Drupal\Core\StringTranslation\TranslatableMarkup), 'error')
#6 /var/www/html/web/core/lib/Drupal/Core/Form/FormErrorHandler.php(23): Drupal\Core\Form\FormErrorHandler->displayErrorMessages(Array, Object(Drupal\Core\Form\FormState))
#7 /var/www/html/web/core/lib/Drupal/Core/Form/FormValidator.php(199): Drupal\Core\Form\FormErrorHandler->handleFormErrors(Array, Object(Drupal\Core\Form\FormState))
#8 /var/www/html/web/core/lib/Drupal/Core/Form/FormValidator.php(119): Drupal\Core\Form\FormValidator->finalizeValidation(Array, Object(Drupal\Core\Form\FormState), 'tmgmt_job_edit_...')
#9 /var/www/html/web/core/lib/Drupal/Core/Form/FormBuilder.php(593): Drupal\Core\Form\FormValidator->validateForm('tmgmt_job_edit_...', Array, Object(Drupal\Core\Form\FormState))
#10 /var/www/html/web/core/lib/Drupal/Core/Form/FormBuilder.php(325): Drupal\Core\Form\FormBuilder->processForm('tmgmt_job_edit_...', Array, Object(Drupal\Core\Form\FormState))
#11 /var/www/html/web/core/lib/Drupal/Core/Controller/FormController.php(73): Drupal\Core\Form\FormBuilder->buildForm(Object(Drupal\tmgmt\Form\JobForm), Object(Drupal\Core\Form\FormState))
#12 [internal function]: Drupal\Core\Controller\FormController->getContentResult(Object(Symfony\Component\HttpFoundation\Request), Object(Drupal\Core\Routing\RouteMatch))
#13 /var/www/html/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array(Array, Array)
#14 /var/www/html/web/core/lib/Drupal/Core/Render/Renderer.php(580): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#15 /var/www/html/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(124): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure))
#16 /var/www/html/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array)
#17 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(169): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#18 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(81): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1)
#19 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/Session.php(58): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#20 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#21 /var/www/html/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#22 /var/www/html/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#23 /var/www/html/web/modules/contrib/cdn/src/StackMiddleware/DuplicateContentPreventionMiddleware.php(130): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#24 /var/www/html/vendor/asm89/stack-cors/src/Asm89/Stack/Cors.php(49): Drupal\cdn\StackMiddleware\DuplicateContentPreventionMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#25 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Asm89\Stack\Cors->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#26 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#27 /var/www/html/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#28 /var/www/html/web/core/lib/Drupal/Core/DrupalKernel.php(718): Stack\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#29 /var/www/html/web/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request))
#30 {main}

Proposed resolution

Error message needs string instead of URL.
MicrosoftTranslator.php
line:- 115,122

--- a/src/Plugin/tmgmt/Translator/MicrosoftTranslator.php
+++ b/src/Plugin/tmgmt/Translator/MicrosoftTranslator.php
@@ -111,14 +111,14 @@ class MicrosoftTranslator extends TranslatorPluginBase implements ContainerFacto
       catch (TMGMTException $e) {
         return AvailableResult::no(t('@translator is not available. Make sure it is properly <a href=:configured>configured</a>.', [
           '@translator' => $translator->label(),
-          ':configured' => $translator->toUrl(),
+          ':configured' => $translator->toUrl()->toString(),
         ]));
       }
 
     }
     return AvailableResult::no(t('@translator is not available. Make sure it is properly <a href=:configured>configured</a>.', [
       '@translator' => $translator->label(),
-      ':configured' => $translator->toUrl(),
+      ':configured' => $translator->toUrl()->toString(),
     ]));
🐛 Bug report
Status

Fixed

Version

1.1

Component

Code

Created by

🇮🇳India jigish.addweb

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

Comments & Activities

Production build 0.71.5 2024