Problem/Motivation

The website encountered an unexpected error. Please try again later.

TypeError: htmlspecialchars(): Argument #1 ($string) must be of type string, array given in htmlspecialchars() (line 432 of core/lib/Drupal/Component/Utility/Html.php).

Drupal\Component\Utility\Html::escape() (Line: 746)
Drupal\Core\Render\Renderer->ensureMarkupIsSafe() (Line: 380)
Drupal\Core\Render\Renderer->doRender() (Line: 204)
Drupal\Core\Render\Renderer->render() (Line: 477)
Drupal\Core\Template\TwigExtension->escapeFilter() (Line: 108)
__TwigTemplate_e5855530e7fbec63717c5b7f62266e92->doDisplay() (Line: 394)
Twig\Template->displayWithErrorHandling() (Line: 367)
Twig\Template->display() (Line: 379)
Twig\Template->render() (Line: 40)
Twig\TemplateWrapper->render() (Line: 53)
twig_render_template() (Line: 372)
Drupal\Core\Theme\ThemeManager->render() (Line: 433)
Drupal\Core\Render\Renderer->doRender() (Line: 204)
Drupal\Core\Render\Renderer->render() (Line: 477)
Drupal\Core\Template\TwigExtension->escapeFilter() (Line: 49)
__TwigTemplate_1655dd0a3f5fb2c6720a86715af95179->doDisplay() (Line: 394)
Twig\Template->displayWithErrorHandling() (Line: 367)
Twig\Template->display() (Line: 379)
Twig\Template->render() (Line: 40)
Twig\TemplateWrapper->render() (Line: 53)
twig_render_template() (Line: 372)
Drupal\Core\Theme\ThemeManager->render() (Line: 433)
Drupal\Core\Render\Renderer->doRender() (Line: 204)
Drupal\Core\Render\Renderer->render() (Line: 477)
Drupal\Core\Template\TwigExtension->escapeFilter() (Line: 75)
__TwigTemplate_4fe24c3264bfa927cbfc8d76bf381f1f->doDisplay() (Line: 394)
Twig\Template->displayWithErrorHandling() (Line: 367)
Twig\Template->display() (Line: 379)
Twig\Template->render() (Line: 40)
Twig\TemplateWrapper->render() (Line: 53)
twig_render_template() (Line: 372)
Drupal\Core\Theme\ThemeManager->render() (Line: 433)
Drupal\Core\Render\Renderer->doRender() (Line: 204)
Drupal\Core\Render\Renderer->render() (Line: 477)
Drupal\Core\Template\TwigExtension->escapeFilter() (Line: 86)
__TwigTemplate_39dd38302057428f2820c1bb328f7210->block_content() (Line: 171)
Twig\Template->displayBlock() (Line: 70)
__TwigTemplate_39dd38302057428f2820c1bb328f7210->doDisplay() (Line: 394)
Twig\Template->displayWithErrorHandling() (Line: 367)
Twig\Template->display() (Line: 379)
Twig\Template->render() (Line: 40)
Twig\TemplateWrapper->render() (Line: 53)
twig_render_template() (Line: 372)
Drupal\Core\Theme\ThemeManager->render() (Line: 433)
Drupal\Core\Render\Renderer->doRender() (Line: 446)
Drupal\Core\Render\Renderer->doRender() (Line: 204)
Drupal\Core\Render\Renderer->render() (Line: 477)
Drupal\Core\Template\TwigExtension->escapeFilter() (Line: 1788)
__TwigTemplate_edfe8ca849427c285539a8220c83af6c->block_page_top() (Line: 171)
Twig\Template->displayBlock() (Line: 850)
__TwigTemplate_edfe8ca849427c285539a8220c83af6c->block_page_container() (Line: 171)
Twig\Template->displayBlock() (Line: 85)
__TwigTemplate_edfe8ca849427c285539a8220c83af6c->doDisplay() (Line: 394)
Twig\Template->displayWithErrorHandling() (Line: 367)
Twig\Template->display() (Line: 44)
__TwigTemplate_27d9c5dcd40f166b614e24f40b1e47a0->doDisplay() (Line: 394)
Twig\Template->displayWithErrorHandling() (Line: 367)
Twig\Template->display() (Line: 379)
Twig\Template->render() (Line: 40)
Twig\TemplateWrapper->render() (Line: 53)
twig_render_template() (Line: 372)
Drupal\Core\Theme\ThemeManager->render() (Line: 433)
Drupal\Core\Render\Renderer->doRender() (Line: 204)
Drupal\Core\Render\Renderer->render() (Line: 477)
Drupal\Core\Template\TwigExtension->escapeFilter() (Line: 86)
__TwigTemplate_841677ef7a6f574ca39b7d2f4d1ac334->doDisplay() (Line: 394)
Twig\Template->displayWithErrorHandling() (Line: 367)
Twig\Template->display() (Line: 379)
Twig\Template->render() (Line: 40)
Twig\TemplateWrapper->render() (Line: 53)
twig_render_template() (Line: 372)
Drupal\Core\Theme\ThemeManager->render() (Line: 433)
Drupal\Core\Render\Renderer->doRender() (Line: 204)
Drupal\Core\Render\Renderer->render() (Line: 158)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 580)
Drupal\Core\Render\Renderer->executeInRenderContext() (Line: 159)
Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse() (Line: 90)
Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray()
call_user_func() (Line: 111)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch() (Line: 168)
Symfony\Component\HttpKernel\HttpKernel->handleRaw() (Line: 74)
Symfony\Component\HttpKernel\HttpKernel->handle() (Line: 58)
Drupal\Core\StackMiddleware\Session->handle() (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle() (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass() (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle() (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle() (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle() (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle() (Line: 686)
Drupal\Core\DrupalKernel->handle() (Line: 19)

Steps to reproduce

D.10.0.9

1. install mega menu
2. add a mega menu (in my case to main navigation)
3. edit/move a menu entry (of main navigation) in the hierarchy
4. error (s. above)
(cleared caches between all steps)

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

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

maxilein created an issue. See original summary.

maxilein’s picture

I can edit that menu when the better mega menu is not installed.

agunjan085’s picture

Assigned: Unassigned » agunjan085
themodularlab’s picture

Looks like this might be an issue with Core or at least a conflict between TB and Core. See https://www.drupal.org/project/drupal/issues/3352384. While that issue is flagged as 9.5 the patch and issue still apply to D10. I'm currently investigating to see what can be done about this.

themodularlab’s picture

Version: 2.0.0-alpha4 » 2.0.0-alpha6
Priority: Normal » Critical
Status: Active » Postponed (maintainer needs more info)

This is definitely an issue with Core. I don't think this is anything that is wrong or done incorrectly with TB Mega Menu related to this bug . Even after removing any references to functions that use the escape() function or htmlspecialchars(), etc. I still encounter the error. And it only happens after saving the menu from the core menu manager (and not TB).

Disregard. My previous statement. How we were handling processing of the caption was causing some issues. I'm going to post an MR for review here shortly.

  • themodularlab committed 0d04acba on bugfix/TBMM-3366359
    git commit -m 'Issue #3366359 by themodularlab: After installing: error...

  • themodularlab committed c282baac on 3.x
    git commit -m 'Issue #3366359 by themodularlab: After installing: error...

  • themodularlab committed 0d04acba on 3.x
    git commit -m 'Issue #3366359 by themodularlab: After installing: error...

  • themodularlab committed be412a2f on 3.x
    git commit -m 'Issue #3366359 by themodularlab: After installing: error...

  • themodularlab committed 88d431fe on 2.x
    Issue #3366359 by themodularlab: After installing: error on edit and...
themodularlab’s picture

Status: Postponed (maintainer needs more info) » Fixed
agunjan085’s picture

Assigned: agunjan085 » Unassigned
nikathone’s picture

StatusFileSize
new129 KB

It looks like this was partially fixed. I just experienced

TypeError: strlen(): Argument #1 ($string) must be of type string, array given in strlen() (line 477 of /code/web/core/lib/Drupal/Component/Utility/Unicode.php)
#0 /code/web/core/lib/Drupal/Component/Utility/Unicode.php(477): strlen(Array)
#1 /code/web/core/lib/Drupal/Component/Utility/Xss.php(65): Drupal\Component\Utility\Unicode::validateUtf8(Array)
#2 /code/web/modules/contrib/tb_megamenu/src/Entity/MegaMenuConfig.php(176): Drupal\Component\Utility\Xss::filter(Array)
#3 /code/web/modules/contrib/tb_megamenu/src/TBMegaMenuBuilder.php(149): Drupal\tb_megamenu\Entity\MegaMenuConfig->getMenuConfig()
#4 /code/web/modules/contrib/tb_megamenu/includes/tb_megamenu.theme.inc(254): Drupal\tb_megamenu\TBMegaMenuBuilder->getMenuConfig('main', '...')
#5 [internal function]: template_preprocess_tb_megamenu(Array, 'tb_megamenu', Array)
#6 /code/web/core/lib/Drupal/Core/Theme/ThemeManager.php(287): call_user_func_array('template_prepro...', Array)

Code screenshot

themodularlab’s picture

@nikathone,

Are you using captions? How we were previously handling captions ended up triggering an issue that's occurring in core so I had to refactor it a bit to work around it. My guess is that if you are using captions. It may be trying to pass that as an array because that's how it was orginally being set. You may just need to go into the TB menu settings, resave (hopefully not re-input captions), and then clear caches.

If that doesn't fix the issue, let me know and I can investigate further.

yospyn’s picture

Hi @themodularlab the problem is we can't get into TB menu settings either. I can get to /admin/structure/tb-megamenu, but when I edit the megamenu I get a white screen. Anything using the front-end theme is broke, as I can't even log into the site.

nikathone’s picture

StatusFileSize
new1.31 KB

We had to apply a local patch for the time being. Not sure if this is the right approach though.

themodularlab’s picture

@yospyn, We did release a new alpha of for the 2.x and the 3.x branch that should have addressed the white screen issues. You may need to try @nikathone's patch.

@nikathone,
I'll look to add your patch and see what other improvements we can make here.

Sorry for the issues everyone is having.

  • themodularlab committed 9a6f4d22 on bugfix/TBMM-3366359-2x authored by nikathone
    Issue #3366359 by nikathone, themodularlab: After installing: error on...

  • themodularlab committed 6554a229 on bugfix/TBMM-3366359-2x authored by nikathone
    Issue #3366359 by nikathone, themodularlab: After installing: error on...

  • themodularlab committed 856ddb24 on bugfix/TBMM-3366359
    Issue #3366359 by nikathone, themodularlab: After installing: error on...
themodularlab’s picture

Status: Fixed » Needs review

@yospyn,

I added a merge request for both 2.x (d8/9) and 3.x (d10). Let me know know if these fix your issues. Here's a patch from the MR for each version:

2.x: https://git.drupalcode.org/project/tb_megamenu/-/merge_requests/74/diffs...
3.x: https://git.drupalcode.org/project/tb_megamenu/-/merge_requests/73/diffs...

I'm moving this to Needs Review.

@nikathone,

Thanks again for your patch. I made a couple of adjustments in order to account for arrays AND to maintain the sanitization of the text since it allows some html.

nikathone’s picture

@themodularlab I think there is no need to use Xss::filter($caption['#plain_text']); because drupal should take care of that. See https://git.drupalcode.org/project/drupal/-/blob/11.x/core/lib/Drupal/Co... and https://git.drupalcode.org/project/drupal/-/blob/11.x/core/lib/Drupal/Co.... This means you can safely do $config[$key]['item_config']['caption'] = $caption; when caption is an array.

I think I think doing

$caption = $value['item_config']['caption'] ?? NULL;
$config[$key]['item_config']['caption'] = is_string($caption) ? Xss::filter($caption) : $caption;

should be enough unless caption is not supposed to be set to NULL. In this case they should some validation somewhere else in the code to stop this from happening.

Also if some HTML can be allowed in the caption string then I think the #markup property should be used instead of #plain_text

themodularlab’s picture

Status: Needs review » Fixed

  • themodularlab committed 05127e76 on 3.x
    Issue #3366359 by nikathone, themodularlab: After installing: error on...
themodularlab’s picture

Version: 2.0.0-alpha6 » 3.0.0-alpha2

Status: Fixed » Closed (fixed)

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