TypeError: strlen(): Argument #1 ($string) must be of type string, array given in strlen()

Created on 1 July 2024, 6 months ago
Updated 26 August 2024, 4 months ago

Problem/Motivation

I've added a custom attribute of type formatted text to a menu link attribute. While the newly added attribute appears correctly on the menu link creation page, I encounter the following error after saving and attempting to edit the same menu link:

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

Steps to reproduce

Install menu_link_attributes
Add custom attribute of type formatted text in => admin/config/menu_link_attributes/config
Create new menu link item and save
Try to edit the same menu link and oberve the error.

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

๐Ÿ› Bug report
Status

Postponed: needs info

Version

1.0

Component

Code

Created by

๐Ÿ‡บ๐Ÿ‡ธUnited States ramu_bharu Bridgewater, Massachusetts

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

Comments & Activities

  • Issue created by @ramu_bharu
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States ramu_bharu Bridgewater, Massachusetts
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia sarwan_verma

    Hi @ramu_bharu,
    I have resolve this issue "TypeError: strlen(): Argument #1 ($string) must be of type string, array given in strlen()" and also attache patch ,
    kindly review and verify .

  • Status changed to Needs review 6 months ago
  • Assigned to Grevil
  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany Anybody Porta Westfalica

    @grevil: Could you also take a short look at this, before we tag a new D11 compatible release?

  • Status changed to Needs work 4 months ago
  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany Anybody Porta Westfalica

    Should be a MR and code style seems to be wrong

  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany Grevil

    I've added a custom attribute of type formatted text [...]

    There is no form element of type formatted text / formatted_text, see https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Render%21... for a full list of all form elements. Did you mean to add a field of type textfield / textarea? But of course, a wrong type shouldn't throw an error. I'll take a look.

  • Issue was unassigned.
  • Status changed to Postponed: needs info 4 months ago
  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany Grevil

    Can not reproduce this issue. Using the incorrect "formatted_text" type, simply doesn't render the form element as expected. Maybe the indentation of the configuration throws an internal YAML error which isn't catched?

    @ramu_bharu, could you give us further information to reproduce?

    PHP Version, Drupal Version, Your configuration in (/admin/config/menu_link_attributes/config).

  • ๐Ÿ‡ง๐Ÿ‡ชBelgium setki

    I have this same error.
    I installed latest version of all: Drupal 10.3.2 / PHP 8.2.12 / 10.4.32-MariaDB

    It is triggerd when i use a special character (unicode), in casu รช in the input field that is provided by a URL parameter like :...?parm=รชtre

    TypeError: strlen(): Argument #1 ($string) must be of type string, array given in strlen() (line 395 of core\lib\Drupal\Component\Utility\Unicode.php).
    Drupal\Component\Utility\Unicode::validateUtf8(Array) (Line: 65)
    Drupal\Component\Utility\Xss::filter(Array, Array) (Line: 841)
    Drupal\Core\Render\Renderer->ensureMarkupIsSafe(Array) (Line: 438)
    Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 248)
    Drupal\Core\Render\Renderer->render(Array, ) (Line: 238)
    Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 638)
    Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 231)
    Drupal\Core\Render\MainContent\HtmlRenderer->prepare(Array, Object, Object) (Line: 128)
    Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse(Array, Object, Object) (Line: 90)
    Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object, 'kernel.view', Object)
    call_user_func(Array, Object, 'kernel.view', Object) (Line: 111)
    Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object, 'kernel.view') (Line: 186)
    Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 76)
    Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 53)
    Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
    Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 28)
    Drupal\Core\StackMiddleware\ContentLength->handle(Object, 1, 1) (Line: 32)
    Drupal\big_pipe\StackMiddleware\ContentLength->handle(Object, 1, 1) (Line: 48)
    Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
    Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 36)
    Drupal\Core\StackMiddleware\AjaxPageState->handle(Object, 1, 1) (Line: 51)
    Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object, 1, 1) (Line: 741)
    Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany Grevil

    Thanks @setki!

    Could you share your configuration in "admin/config/menu_link_attributes/config" and provide clear steps to reproduce?

Production build 0.71.5 2024