Error: [] operator not supported for strings in Drupal\menu_block\Plugin\Block\MenuBlock->getLinkTitleFromLink() (line 612 of modules/contrib/menu_block/src/Plugin/Block/MenuBlock.php).

Created on 16 July 2024, 4 months ago
Updated 19 September 2024, about 2 months ago

I have an error in my third level menu block that is only active on certain pages.

Error: [] operator not supported for strings in Drupal\menu_block\Plugin\Block\MenuBlock->getLinkTitleFromLink() (line 612 of modules/contrib/menu_block/src/Plugin/Block/MenuBlock.php).

My drupal is 10.3.0 with php 8.1.

🐛 Bug report
Status

RTBC

Version

1.0

Component

Code

Created by

🇪🇸Spain ssantaeugenia

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

Merge Requests

Comments & Activities

  • Issue created by @ssantaeugenia
  • 🇪🇸Spain ssantaeugenia

    I am attaching a patch that solves the problem in case anyone encounters the same problem.

  • Status changed to RTBC 4 months ago
  • 🇺🇸United States wylbur Minneapolis, Minnesota, USA

    Confirming that we also experienced this error:
    - drupal 10.3.1
    - php 8.2
    - menu_block 8.x-1.11
    Applying the patch resolved the php errors.

    Marking this as RTBC

  • First commit to issue fork.
  • Merge request !27Issue #3461766 "Error operator" → (Open) created by ankitv18
  • Pipeline finished with Success
    4 months ago
    Total: 186s
    #240135
  • 🇺🇸United States daletrexel Minnesota, USA

    Can confirm experiencing the same error and that patch/MR work to resolve the problem.

  • 🇺🇸United States daletrexel Minnesota, USA

    Digging into the source of the problem on my site, I believe that the problem may be due to inconsistency in the Link Attributes Widget module data schema (perhaps a change that wasn't fully migrated?).

    We use the Link Attributes Widget module , which allows you to add attributes such as classes to menu links. For the page that was throwing this menu block error, re-saving the parent menu item resolved the error and allowed the page to show.

    In the database, that parent page's 'link_options' field in the 'menu_link_content_data' table looked like this prior to re-saving:
    a:1:{s:10:"attributes";a:1:{s:5:"class";s:0:"";}}

    And like this after saving:
    a:1:{s:10:"attributes";a:1:{s:5:"class";a:1:{i:0;s:0:"";}}}

    The class is changed from a string to an array, allowing $attributes['class'][] = 'menu-item--active-trail'; to work without error.

    The current patch/MR approach of setting $attributes['class'] to an empty array, regardless of what was there before seems to work for us, but I wonder if it's potentially removing classes that other users may want to keep?

    I'm not 100% certain Link Attributes Widget is to blame for the ultimate problem here, but it seems likely given what is involved.

  • 🇩🇪Germany Anybody Porta Westfalica

    NW as of #8 the current implementation may override values. And it's unclear what's the root cause.

  • First commit to issue fork.
  • Merge request !29Update file MenuBlock.php → (Open) created by hitfactory
  • Pipeline finished with Success
    about 1 month ago
    Total: 179s
    #298784
  • 🇨🇦Canada AaronChristian Kelowna, BC

    +1, also ran into this issue.

    Same PHP & module combinations as mentioned previously.

Production build 0.71.5 2024