AssetRenderer.php in Entity Print 8.2
File
src/Asset/AssetRenderer.php
View source
<?php
namespace Drupal\entity_print\Asset;
use Drupal\Core\Asset\AssetCollectionRendererInterface;
use Drupal\Core\Asset\AssetResolverInterface;
use Drupal\Core\Asset\AttachedAssets;
class AssetRenderer implements AssetRendererInterface {
protected $assetResolver;
protected $cssRenderer;
protected $assetCollector;
public function __construct(AssetResolverInterface $asset_resolver, AssetCollectionRendererInterface $css_renderer, AssetCollectorInterface $asset_collector) {
$this->assetResolver = $asset_resolver;
$this->cssRenderer = $css_renderer;
$this->assetCollector = $asset_collector;
}
public function render(array $entities, $use_default_css = TRUE, $optimize_css = TRUE) {
$build['#attached']['library'] = [];
if ($use_default_css) {
$build['#attached']['library'][] = 'entity_print/default';
}
$build['#attached']['library'] = array_merge($this->assetCollector
->getCssLibraries($entities), $build['#attached']['library']);
foreach ($build['#attached']['library'] as $key => $library) {
if ($key === '#attached') {
$build['#attached']['library'] = array_merge($build['#attached']['library'], $library['library']);
unset($build['#attached']['library'][$key]);
}
}
$css_assets = $this->assetResolver
->getCssAssets(AttachedAssets::createFromRenderArray($build), $optimize_css);
return $this->cssRenderer
->render($css_assets);
}
}