diff --git a/readme.md b/readme.md index 167b6c920163de6911900125998dc0b05fb34011..82b636776f59648d3c5a78258673ee5bde1e0a62 100644 --- a/readme.md +++ b/readme.md @@ -25,6 +25,9 @@ $render['element'] = [ [ 'data' => '.highlight { background-color: yellow; }', 'group' => CSS_THEME, + 'attributes' => [ + 'media' => 'all', + ] ], ], ], diff --git a/src/Asset/CssCollectionRendererDecorator.php b/src/Asset/CssCollectionRendererDecorator.php index d664ed44b64a5d53ebf7dcd25600eae84acfa055..1754c29d20319aa53fb870f3b13bad2e69469f0b 100644 --- a/src/Asset/CssCollectionRendererDecorator.php +++ b/src/Asset/CssCollectionRendererDecorator.php @@ -76,6 +76,7 @@ class CssCollectionRendererDecorator implements AssetCollectionRendererInterface '#type' => 'html_tag', '#tag' => 'style', '#value' => '', + '#attributes' => [], ]; // Loop through all JS assets. @@ -87,6 +88,10 @@ class CssCollectionRendererDecorator implements AssetCollectionRendererInterface $element = $element_defaults; $element['#value'] = AttachInlineMarkup::create($css_asset['data']); + if (!empty($css_asset['attributes'])) { + $element['#attributes'] += $css_asset['attributes']; + } + if ($this->moduleHandler->moduleExists('csp')) { $allowMethod = $this->config->get('attachinline.settings')->get('csp-allow-method') ?? 'hash'; if ($allowMethod == 'nonce') { diff --git a/src/Asset/JsCollectionRendererDecorator.php b/src/Asset/JsCollectionRendererDecorator.php index 198af56f1babb4d1dc09578bc21d8ee7ba611724..633940294b9e18240029dc0e038862cb5649349a 100644 --- a/src/Asset/JsCollectionRendererDecorator.php +++ b/src/Asset/JsCollectionRendererDecorator.php @@ -76,6 +76,7 @@ class JsCollectionRendererDecorator implements AssetCollectionRendererInterface '#type' => 'html_tag', '#tag' => 'script', '#value' => '', + '#attributes' => [], ]; // Loop through all JS assets. @@ -87,6 +88,10 @@ class JsCollectionRendererDecorator implements AssetCollectionRendererInterface $element = $element_defaults; $element['#value'] = AttachInlineMarkup::create($js_asset['data']); + if (!empty($js_asset['attributes'])) { + $element['#attributes'] += $js_asset['attributes']; + } + if ($this->moduleHandler->moduleExists('csp')) { $allowMethod = $this->config->get('attachinline.settings')->get('csp-allow-method') ?? 'hash'; if ($allowMethod == 'nonce') {