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

Created on 1 August 2025, about 1 month ago

Location:
/admin/structure/page-layout/page_layout_test/builder

Referrer:
/admin/structure/page-layout

Message:

TypeError: ltrim(): Argument #1 ($string) must be of type string, Drupal\Core\StringTranslation\TranslatableMarkup given in ltrim() (line 566 of /web/modules/contrib/display_builder/src/Plugin/display_builder/Island/ComponentLibraryPanel.php).

🐛 Bug report
Status

Active

Version

1.0

Component

Main / Misc.

Created by

🇬🇧United Kingdom juc1

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

Comments & Activities

  • Issue created by @juc1
  • 🇫🇷France pdureau Paris

    Hi Juc1, I am not reproducing. Can you share with us your display builder profile config ?

  • 🇬🇧United Kingdom juc1

    hi, I have not touched the profiles so it is just the default profile, same error for a block display...

  • 🇬🇧United Kingdom juc1

    ah the error happens with my theme - which is a sub theme of https://www.drupal.org/project/ui_suite_daisyui

    It works ok with a different theme.

  • 🇫🇷France pdureau Paris

    ah the error happens with my theme - which is a sub theme of https://www.drupal.org/project/ui_suite_daisyui

    Oh! that's interesting! Can you isolate the SDC which is triggering this error?

  • 🇬🇧United Kingdom juc1

    ok I found it, it was one of my own custom SDC that I had half finished and it was a missing "name" key in the component.yaml that triggered the error. This SDC was there for a few days so it did not cause an error before installing Display Builder but I guess that Display Builder is more sensitive. Anyway fixed, thank you...

  • 🇫🇷France pdureau Paris

    Thanks for the investigation.

    but I guess that Display Builder is more sensitive.

    Display Builder must not be more sensitive than SDC and UI Patterns, so it is something to fix.

  • 🇬🇧United Kingdom juc1

    It would be good if the error message (my first post, above) was more helpful such as mentioning the SDC that is causing the problem, but I am not sure if you can control the error messages.

  • 🇫🇷France pdureau Paris

    It would be good if the error message (my first post, above) was more helpful

    It would be even better without an error message because Display Builder will not trigger errors anymore :) But if it is not possible, I agree a better error message would help.

    @juc1 do you want to propose a fix yourself?

  • 🇫🇷France Grimreaper France 🇫🇷

    No patches or MR here, so status should be active.

  • 🇬🇧United Kingdom juc1

    ok I will have a go, I think the problem might be...

    \display_builder\src\Plugin\display_builder\Island\ComponentLibraryPanel.php, 566

    // Order list ignoring starting '(' that is used for components names that
        // are sub components.
        \uasort($filtered_definitions, static function ($a, $b) {
          // @phpstan-ignore-next-line
          $nameA = \ltrim($a['name'] ?? $a['label'], '(');
    
  • 🇬🇧United Kingdom juc1

    On a quick test this patch seems to fix the problem for me...

    When the Component Library Panel is built, the list of SDCs is sorted alphabetically by the component's "name" key. The ltrim() function is used during this sort process.

    If an SDC is missing its name key, ComponentLibraryPanel.php falls back to using the component's label, which is a TranslatableMarkup object. The ltrim() function expects a string, so passing an object instead of a string causes a fatal error.

    This patch converts the value to a string before it is passed to the ltrim() function. This ensures the ltrim() function always receives the correct data type and prevents the error, allowing the component library to load gracefully.

  • 🇫🇷France pdureau Paris

    Sounds great. Can you do a MR?

  • @juc1 opened merge request.
  • 🇬🇧United Kingdom juc1

    OK have done the MR...

  • 🇫🇷France pdureau Paris

    The problem exists in other parts of Display Builder, so fixing it in

    Argument #4 ($title) must be of type string, Drupal\Core\StringTranslation\TranslatableMarkup given, called in /home/pierre/Projects/Drupal/ui_patterns_2/web/modules/custom/display_builder/src/Plugin/display_builder/Island/BuilderPanel.php on line 173 in Drupal\display_builder\HtmxEvents->onInstanceClick() (line 204 of modules/custom/display_builder/src/HtmxEvents.php).

    I keep it in my side for now to decide if the fix must be done in Display Builder or UI Patterns 2 side.

  • 🇫🇷France pdureau Paris

    Moved to UI Patterns: 🐛 [2.0.7] Fix callback name fallback Active

  • 🇧🇪Belgium mschudders

    I can confirm that I have the same issue when setting up a new drupal project with drupal CMS.
    steps:

     cd drupalcms_displaybuilder
     ddev config --project-type=drupal11 --docroot=web
     ddev start
     ddev composer create-project drupal/cms
    ddev launch
    ddev composer require 'drupal/display_builder:1.0.x-dev@dev' 'drupal/ui_skins:^1.1@alpha'
    ddev drush en display_builder -y

    Then when you enable the default profile on for example "Blog" and when you go to "display builder" you will see this message.

    I have Version: 2.0.8 of ui_patterns in which it the fix isn't yet merged as far as I can see:
    https://www.drupal.org/project/ui_patterns/issues/3540536 🐛 [2.0.7] Fix callback name fallback Active
    https://git.drupalcode.org/project/ui_patterns/-/commits/2.0.x

    @pdureau can you merge it?

    Thanks

  • 🇫🇷France pdureau Paris

    Thanks Michael, we will have a look next week, before alpha5

  • 🇫🇷France pdureau Paris

    @mschudders 🐛 [2.0.7] Fix callback name fallback Active has been merged in UI Patterns 2.0.x branch. Can you try again?

  • 🇬🇧United Kingdom juc1

    Variation of this...

    Location: /admin/structure/block-content/manage/basic/display/default/display-builder

    Message: TypeError: ltrim(): Argument #1 ($string) must be of type string, Drupal\Core\StringTranslation\TranslatableMarkup given in ltrim() (line 475 of /var/www/html/web/modules/contrib/display_builder/src/Plugin/display_builder/Island/ComponentLibraryPanel.php).

    Severity: Error

Production build 0.71.5 2024