TypeError: htmlspecialchars(): Argument #1 ($string) must be of type string

Created on 1 November 2021, over 2 years ago
Updated 17 September 2023, 10 months ago

Problem/Motivation

It seems this one isn't quite revoled.

Broken when upgrading to PHP 8.0 (compatible with D 9.1+) In fact, it's related to issue 3216304

Steps to reproduce

Drupal Version 9.2.7
Web Server Apache/2.4.41 (Ubuntu)
PHP Version 8.01
Database Version 8.0.26-16 MySQL, Percona Server, or equivalent

Apply View any page where better social sharing buttons are displayed.

Error log

TypeError: htmlspecialchars(): Argument #1 ($string) must be of type string, array given in htmlspecialchars() (line 424 of /data/vhosts/caffebatavia.eu/wwwroot/html/java-kitchen-d9/web/core/lib/Drupal/Component/Utility/Html.php)

#0 /data/vhosts/caffebatavia.eu/wwwroot/html/java-kitchen-d9/web/core/lib/Drupal/Component/Utility/Html.php(424): htmlspecialchars(Array, 11, 'UTF-8')
#1 /data/vhosts/caffebatavia.eu/wwwroot/html/java-kitchen-d9/web/modules/contrib/better_social_sharing_buttons/src/Plugin/Block/SocialSharingButtonsBlock.php(194): Drupal\Component\Utility\Html::escape(Array)
#2 /data/vhosts/caffebatavia.eu/wwwroot/html/java-kitchen-d9/web/core/modules/block/src/BlockViewBuilder.php(171): Drupal\better_social_sharing_buttons\Plugin\Block\SocialSharingButtonsBlock->build()
#3 [internal function]: Drupal\block\BlockViewBuilder::preRender(Array)
#4 /data/vhosts/caffebatavia.eu/wwwroot/html/java-kitchen-d9/web/core/lib/Drupal/Core/Security/DoTrustedCallbackTrait.php(101): call_user_func_array(Array, Array)
#5 /data/vhosts/caffebatavia.eu/wwwroot/html/java-kitchen-d9/web/core/lib/Drupal/Core/Render/Renderer.php(786): Drupal\Core\Render\Renderer->doTrustedCallback(Array, Array, 'Render #pre_ren...', 'exception', 'Drupal\\Core\\Ren...')
#6 /data/vhosts/caffebatavia.eu/wwwroot/html/java-kitchen-d9/web/core/lib/Drupal/Core/Render/Renderer.php(377): Drupal\Core\Render\Renderer->doCallback('#pre_render', Array, Array)
#7 /data/vhosts/caffebatavia.eu/wwwroot/html/java-kitchen-d9/web/core/lib/Drupal/Core/Render/Renderer.php(449): Drupal\Core\Render\Renderer->doRender(Array)
#8 /data/vhosts/caffebatavia.eu/wwwroot/html/java-kitchen-d9/web/core/lib/Drupal/Core/Render/Renderer.php(201): Drupal\Core\Render\Renderer->doRender(Array, false)
#9 /data/vhosts/caffebatavia.eu/wwwroot/html/java-kitchen-d9/web/core/lib/Drupal/Core/Template/TwigExtension.php(450): Drupal\Core\Render\Renderer->render(Array)
#10 /data/vhosts/caffebatavia.eu/wwwroot/html/java-kitchen-d9/vendor/twig/twig/src/Environment.php(418) : eval()'d code(116): Drupal\Core\Template\TwigExtension->escapeFilter(Object(Drupal\Core\Template\TwigEnvironment), Array, 'html', NULL, true)
#11 /data/vhosts/caffebatavia.eu/wwwroot/html/java-kitchen-d9/vendor/twig/twig/src/Template.php(405): __TwigTemplate_45ecb7b9f80059d112dd90870c393288abfd63971ae9d31afd63563567596424->doDisplay(Array, Array)
#12 /data/vhosts/caffebatavia.eu/wwwroot/html/java-kitchen-d9/vendor/twig/twig/src/Template.php(378): Twig\Template->displayWithErrorHandling(Array, Array)
#13 /data/vhosts/caffebatavia.eu/wwwroot/html/java-kitchen-d9/vendor/twig/twig/src/Template.php(390): Twig\Template->display(Array)
#14 /data/vhosts/caffebatavia.eu/wwwroot/html/java-kitchen-d9/web/core/themes/engines/twig/twig.engine(65): Twig\Template->render(Array)
#15 /data/vhosts/caffebatavia.eu/wwwroot/html/java-kitchen-d9/web/core/lib/Drupal/Core/Theme/ThemeManager.php(384): twig_render_template('themes/contrib/...', Array)
#16 /data/vhosts/caffebatavia.eu/wwwroot/html/java-kitchen-d9/web/core/lib/Drupal/Core/Render/Renderer.php(436): Drupal\Core\Theme\ThemeManager->render('page', Array)
#17 /data/vhosts/caffebatavia.eu/wwwroot/html/java-kitchen-d9/web/core/lib/Drupal/Core/Render/Renderer.php(201): Drupal\Core\Render\Renderer->doRender(Array, false)
#18 /data/vhosts/caffebatavia.eu/wwwroot/html/java-kitchen-d9/web/core/lib/Drupal/Core/Template/TwigExtension.php(450): Drupal\Core\Render\Renderer->render(Array)
#19 /data/vhosts/caffebatavia.eu/wwwroot/html/java-kitchen-d9/vendor/twig/twig/src/Environment.php(418) : eval()'d code(86): Drupal\Core\Template\TwigExtension->escapeFilter(Object(Drupal\Core\Template\TwigEnvironment), Array, 'html', NULL, true)
#20 /data/vhosts/caffebatavia.eu/wwwroot/html/java-kitchen-d9/vendor/twig/twig/src/Template.php(405): __TwigTemplate_95483ddede52207ed4e4f848d09b4a473bebb78ea72f0b3ae363f4f9ea49b9ff->doDisplay(Array, Array)
#21 /data/vhosts/caffebatavia.eu/wwwroot/html/java-kitchen-d9/vendor/twig/twig/src/Template.php(378): Twig\Template->displayWithErrorHandling(Array, Array)
#22 /data/vhosts/caffebatavia.eu/wwwroot/html/java-kitchen-d9/vendor/twig/twig/src/Template.php(390): Twig\Template->display(Array)
#23 /data/vhosts/caffebatavia.eu/wwwroot/html/java-kitchen-d9/web/core/themes/engines/twig/twig.engine(65): Twig\Template->render(Array)
#24 /data/vhosts/caffebatavia.eu/wwwroot/html/java-kitchen-d9/web/core/lib/Drupal/Core/Theme/ThemeManager.php(384): twig_render_template('themes/contrib/...', Array)
#25 /data/vhosts/caffebatavia.eu/wwwroot/html/java-kitchen-d9/web/core/lib/Drupal/Core/Render/Renderer.php(436): Drupal\Core\Theme\ThemeManager->render('html', Array)
#26 /data/vhosts/caffebatavia.eu/wwwroot/html/java-kitchen-d9/web/core/lib/Drupal/Core/Render/Renderer.php(201): Drupal\Core\Render\Renderer->doRender(Array, false)
#27 /data/vhosts/caffebatavia.eu/wwwroot/html/java-kitchen-d9/web/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php(162): Drupal\Core\Render\Renderer->render(Array)
#28 /data/vhosts/caffebatavia.eu/wwwroot/html/java-kitchen-d9/web/core/lib/Drupal/Core/Render/Renderer.php(578): Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}()
#29 /data/vhosts/caffebatavia.eu/wwwroot/html/java-kitchen-d9/web/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php(163): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure))
#30 /data/vhosts/caffebatavia.eu/wwwroot/html/java-kitchen-d9/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))
#31 [internal function]: Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object(Symfony\Component\HttpKernel\Event\ViewEvent), 'kernel.view', Object(Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher))
#32 /data/vhosts/caffebatavia.eu/wwwroot/html/java-kitchen-d9/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))
#33 /data/vhosts/caffebatavia.eu/wwwroot/html/java-kitchen-d9/vendor/symfony/http-kernel/HttpKernel.php(163): Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object(Symfony\Component\HttpKernel\Event\ViewEvent), 'kernel.view')
#34 /data/vhosts/caffebatavia.eu/wwwroot/html/java-kitchen-d9/vendor/symfony/http-kernel/HttpKernel.php(80): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1)
#35 /data/vhosts/caffebatavia.eu/wwwroot/html/java-kitchen-d9/web/core/lib/Drupal/Core/StackMiddleware/Session.php(57): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#36 /data/vhosts/caffebatavia.eu/wwwroot/html/java-kitchen-d9/web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(47): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#37 /data/vhosts/caffebatavia.eu/wwwroot/html/java-kitchen-d9/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#38 /data/vhosts/caffebatavia.eu/wwwroot/html/java-kitchen-d9/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#39 /data/vhosts/caffebatavia.eu/wwwroot/html/java-kitchen-d9/web/core/modules/ban/src/BanMiddleware.php(50): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#40 /data/vhosts/caffebatavia.eu/wwwroot/html/java-kitchen-d9/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(47): Drupal\ban\BanMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#41 /data/vhosts/caffebatavia.eu/wwwroot/html/java-kitchen-d9/web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(52): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#42 /data/vhosts/caffebatavia.eu/wwwroot/html/java-kitchen-d9/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#43 /data/vhosts/caffebatavia.eu/wwwroot/html/java-kitchen-d9/web/core/lib/Drupal/Core/DrupalKernel.php(717): Stack\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#44 /data/vhosts/caffebatavia.eu/wwwroot/html/java-kitchen-d9/web/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request))
#45 {main}

Proposed resolution

Fix this error and ensure compatibility

πŸ› Bug report
Status

Closed: cannot reproduce

Version

3.2

Component

Code

Created by

Live updates comments and jobs are added and updated live.
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.

Production build 0.69.0 2024