Change record status: 
Project: 
Introduced in branch: 
10.1.x
Introduced in version: 
10.1.0
Description: 

Passing a string of rendered HTML to Drupal\Core\Ajax\AddCssCommand is deprecated, and instead should be provided with arrays of stylesheet attributes.

Before:

  use Drupal\Core\Ajax\AddCssCommand;

  $resource_commands[] = new AddCssCommand($this->renderer->renderPlain($css_render_array));

After:

  use Drupal\Core\Ajax\AddCssCommand;

  $resource_commands[] = new AddCssCommand(array_column($css_render_array, '#attributes'));

  $resource_commands[] = new AddCssCommand([
    ['href' => 'path/to/file.css', 'media' => 'all'],
    ['href' => 'path/to/screen.css', 'media' => 'screen'],
  ]);
Impacts: 
Module developers
Themers

Comments

gapple’s picture

Inline CSS can still be accomplished by providing a rendered HTML string to AppendCommand instead of AddCssCommand,

An 'unsafe-inline' exception will be required for the originating page's style-src Content Security Policy directive.