D11 deprecation: AddCssCommand receives a Markup string instead of an array

Created on 20 May 2025, about 1 month ago

When items using bg_image_formatter are present in a layout, dragging and dropping of any item in the layout will triggers a AJAX HTTP 500 error (in the console).

Drupal\\Core\\Ajax\\AddCssCommand::__construct(): Argument #1 ($styles) must be of type array, Drupal\\Core\\Render\\Markup given, called in /app/web/modules/contrib/bg_image_formatter/bg_image_formatter.module on line 39

This is likely the result of a core deprecation. AddCssCommand is receiving a Markup string instead of an array, which as of 10.1.0, is not allowed: https://www.drupal.org/node/3154948 . It looks like other modules may be facing a similar problem: https://www.drupal.org/project/drupal/issues/3389148 🐛 No way to add inline CSS to AJAX responses Needs review

To mitigate this, I've applied the following adjustment:

 $data[] = (new AddCssCommand(['data' => $style_tag]))->render()

However, this introduces a new error in the console:

An error occurred during the execution of the Ajax response: TypeError: response.data.map is not a function

Environment:

  • Drupal Core: 11.x
  • bg_image_formatter: latest dev release
  • Layout Builder: enabled
🐛 Bug report
Status

Active

Version

1.0

Component

Code

Created by

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024