Problem/Motivation

I am seeing this on any page where simple_popup_block is displayed.

Full text of the error is:

Warning: htmlspecialchars() expects parameter 1 to be string, array given in Drupal\Component\Utility\Html::escape() (line 424 of /code/web/core/lib/Drupal/Component/Utility/Html.php)
#0 /code/web/core/includes/bootstrap.inc(600): _drupal_error_handler_real(2, 'htmlspecialchar...', '/code/web/core/...', 424, Array)
#1 [internal function]: _drupal_error_handler(2, 'htmlspecialchar...', '/code/web/core/...', 424, Array)
#2 /code/web/core/lib/Drupal/Component/Utility/Html.php(424): htmlspecialchars(Array, 11, 'UTF-8')
#3 [internal function]: Drupal\Component\Utility\Html::escape(Array)
#4 /code/web/modules/contrib/simple_popup_blocks/simple_popup_blocks.module(58): array_map('Drupal\\Componen...', Array)
#5 /code/web/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php(297): simple_popup_blocks_page_attachments(Array)
#6 /code/web/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php(273): Drupal\Core\Render\MainContent\HtmlRenderer->invokePageAttachmentHooks(Array)
#7 /code/web/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php(117): Drupal\Core\Render\MainContent\HtmlRenderer->prepare(Array, Object(Symfony\Component\HttpFoundation\Request), Object(Drupal\Core\Routing\CurrentRouteMatch))
#8 /code/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))
#9 [internal function]: Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object(Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent), 'kernel.view', Object(Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher))
#10 /code/web/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php(111): call_user_func(Array, Object(Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent), 'kernel.view', Object(Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher))
#11 /code/vendor/symfony/http-kernel/HttpKernel.php(156): Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch('kernel.view', Object(Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent))
#12 /code/vendor/symfony/http-kernel/HttpKernel.php(68): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1)
#13 /code/web/core/lib/Drupal/Core/StackMiddleware/Session.php(57): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#14 /code/web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(47): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#15 /code/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(47): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#16 /code/web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(52): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#17 /code/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#18 /code/web/core/lib/Drupal/Core/DrupalKernel.php(708): Stack\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#19 /code/web/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request))
#20 {main}

It looks like the entry in config is causing the issue:

_core:
  default_config_hash: XBucOv5lwgVzHOV3HANT7Ekf7Ul1Ah4LnT-LjsPmO_I

because that piece of config is turned into an array and not a string when the config is loaded.

Steps to reproduce

Add a simple block to a page, load the page, and check the "Recent log message".

Proposed resolution

Unset the

$data['_core']

hash before calling the array_map function. This doesn't need to be communicated as a setting anyway, I'd imagine.

Remaining tasks

Add patch/fork.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

mariacha1 created an issue. See original summary.

mariacha1’s picture

Status: Active » Needs review
damienmckenna’s picture

StatusFileSize
new544 bytes

The same change as the MR in patch format.

damienmckenna’s picture

StatusFileSize
new893 bytes

The patch fixes one of the errors, but another one shows. It might be worth changing this line entirely.

mariacha1’s picture

Status: Needs review » Reviewed & tested by the community

Yep, that's more robust for sure. Tested out patch 5 and it works great!

vacho’s picture

In my case this issue happen when the block that popup should show, is missing.

vacho’s picture

StatusFileSize
new884 bytes

This patch fixes for me any issue. this add a validation to empty values.

vacho’s picture

StatusFileSize
new1.01 KB

Fixing missing HTML class

joelseguin’s picture

Thanks - I've applied and tested patch #9 on a D9.4.8. Seems to remove all warnings and the module works as expected.

btown’s picture

I'm just wondering if this is going to be rolled into an update soon?

Thanks!

vidwood’s picture

Honestly it's a bit discouraging that 3.1.0 is out and still has this same issue.
Either way, I'd just like to report that patch #9 seems to fix the problem on D9.4.9 running simple_popup_blocks 3.1.0.

I suppose the version parameter on this issue might need updating. Or a clone or child issue added. I'm not 100% sure which would be most proper, so to avoid creating trash, I'm just leaving this comment here for now.

berdir’s picture

Version: 8.x-2.8 » 8.x-3.x-dev

Issues should be created against the dev version in 99% of the cases, unless it for some reason really only applies to a specific version. Updating accordingly.

mrinalini9’s picture

Hi,

I have tested patch #9 with Drupal version: 9.5.2 and PHP: 8.1, it's working for me.

Thanks!

i-trokhanenko’s picture

Status: Reviewed & tested by the community » Patch (to be ported)

Thanks, I'll commit the #9 patch.

  • i-trokhanenko committed d636ad76 on 8.x-3.x
    Issue #3267864 by mariacha1, vacho, damienmckenna: Warning:...
i-trokhanenko’s picture

Status: Patch (to be ported) » Fixed

Thanks!

Status: Fixed » Closed (fixed)

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