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.
| Comment | File | Size | Author |
|---|---|---|---|
| #9 | simple_popup_blocks-n3267864-9.patch | 1.01 KB | vacho |
Issue fork simple_popup_blocks-3267864
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
Comment #3
mariacha1 commentedComment #4
damienmckennaThe same change as the MR in patch format.
Comment #5
damienmckennaThe patch fixes one of the errors, but another one shows. It might be worth changing this line entirely.
Comment #6
mariacha1 commentedYep, that's more robust for sure. Tested out patch 5 and it works great!
Comment #7
vacho commentedIn my case this issue happen when the block that popup should show, is missing.
Comment #8
vacho commentedThis patch fixes for me any issue. this add a validation to empty values.
Comment #9
vacho commentedFixing missing HTML class
Comment #10
joelseguinThanks - I've applied and tested patch #9 on a D9.4.8. Seems to remove all warnings and the module works as expected.
Comment #11
btown commentedI'm just wondering if this is going to be rolled into an update soon?
Thanks!
Comment #12
vidwood commentedHonestly 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.
Comment #13
berdirIssues 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.
Comment #14
mrinalini9 commentedHi,
I have tested patch #9 with Drupal version: 9.5.2 and PHP: 8.1, it's working for me.
Thanks!
Comment #15
i-trokhanenkoThanks, I'll commit the #9 patch.
Comment #17
i-trokhanenkoThanks!