-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: ✨ add asset renderer decorators
- the decorators remove the querystring from library assets with noquery attribute
- Loading branch information
Showing
8 changed files
with
119 additions
and
30 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
...l-companion/modules/uebertool_asset_renderer/src/Asset/CssCollectionRendererDecorator.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace Drupal\uebertool_asset_renderer\Asset; | ||
|
||
use Drupal\Core\Asset\AssetCollectionRendererInterface; | ||
|
||
/** | ||
* Optimizes a CSS asset. | ||
*/ | ||
class CssCollectionRendererDecorator implements AssetCollectionRendererInterface { | ||
|
||
public function __construct(protected AssetCollectionRendererInterface $prototype) {} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function render(array $css_assets) { | ||
foreach ($css_assets as $css_asset) { | ||
if (isset($css_asset['noquery'])) { | ||
// Setting preprocessed to TRUE will prevent Drupal from prepending the querystring. | ||
$css_asset['preprocessed'] = TRUE; | ||
} | ||
} | ||
|
||
$elements = $this->prototype->render($css_assets); | ||
|
||
return $elements; | ||
} | ||
|
||
} |
30 changes: 30 additions & 0 deletions
30
...ol-companion/modules/uebertool_asset_renderer/src/Asset/JsCollectionRendererDecorator.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace Drupal\uebertool_asset_renderer\Asset; | ||
|
||
use Drupal\Core\Asset\AssetCollectionRendererInterface; | ||
|
||
/** | ||
* Optimizes a JS asset. | ||
*/ | ||
class JsCollectionRendererDecorator implements AssetCollectionRendererInterface { | ||
|
||
public function __construct(protected AssetCollectionRendererInterface $prototype) {} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function render(array $js_assets) { | ||
foreach ($js_assets as $js_asset) { | ||
if (isset($js_asset['noquery'])) { | ||
// Setting preprocessed to TRUE will prevent Drupal from prepending the querystring. | ||
$js_asset['preprocessed'] = TRUE; | ||
} | ||
} | ||
|
||
$elements = $this->prototype->render($js_assets); | ||
|
||
return $elements; | ||
} | ||
|
||
} |
5 changes: 5 additions & 0 deletions
5
...es/uebertool-companion/modules/uebertool_asset_renderer/uebertool_asset_renderer.info.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
name: UEbertool Asset Renderer | ||
type: module | ||
description: Remove version query from custom theme assets. Use noquery = true in your theme's libraries.yml. | ||
package: UEbertool | ||
core_version_requirement: ^9 || ^10 |
9 changes: 9 additions & 0 deletions
9
...ebertool-companion/modules/uebertool_asset_renderer/uebertool_asset_renderer.services.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
services: | ||
uebertool_asset_renderer.js.collection_renderer: | ||
class: Drupal\uebertool_asset_renderer\Asset\JsCollectionRendererDecorator | ||
decorates: asset.js.collection_renderer | ||
arguments: [ '@uebertool_asset_renderer.js.collection_renderer.inner' ] | ||
uebertool_asset_renderer.css.collection_renderer: | ||
class: Drupal\uebertool_asset_renderer\Asset\CssCollectionRendererDecorator | ||
decorates: asset.css.collection_renderer | ||
arguments: [ '@uebertool_asset_renderer.css.collection_renderer.inner' ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters