By gapple on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
10.1.x
Introduced in version:
10.1.0
Issue links:
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
Inline CSS
Inline CSS can still be accomplished by providing a rendered HTML string to
AppendCommandinstead ofAddCssCommand,An
'unsafe-inline'exception will be required for the originating page'sstyle-srcContent Security Policy directive.