public function AssetRenderer::render in Entity Print 8.2
Renders the CSS assets for the given entities.
Parameters
\Drupal\Core\Entity\EntityInterface[] $entities: An array of entities for whose assets we want to render.
bool $use_default_css: TRUE to add in the global CSS otherwise FALSE.
bool $optimize_css: TRUE to optimise the CSS otherwise FALSE.
Return value
array The renderable array for the assets.
Overrides AssetRendererInterface::render
File
- src/
Asset/ AssetRenderer.php, line 54
Class
- AssetRenderer
- Render CSS assets for the entities being printed.
Namespace
Drupal\entity_print\AssetCode
public function render(array $entities, $use_default_css = TRUE, $optimize_css = TRUE) {
$build['#attached']['library'] = [];
// Inject some generic CSS across all templates.
if ($use_default_css) {
$build['#attached']['library'][] = 'entity_print/default';
}
$build['#attached']['library'] = array_merge($this->assetCollector
->getCssLibraries($entities), $build['#attached']['library']);
// This keeps BC for the CSS alter event which used to provide a render
// array but now passes a list of libraries. So, if users of the API have
// treated it like a render array, we move the libraries into the correct
// place.
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);
}