protected function RendererBase::addCss in Entity Print 8
Inject the relevant css for the template.
You can specify CSS files to be included per entity type and bundle in your themes css file. This code uses your current theme which is likely to be the front end theme.
Examples:
entity_print: all: 'yourtheme/all-pdfs', commerce_order: all: 'yourtheme/orders' node: article: 'yourtheme/article-pdf'
Parameters
array $render: The renderable array.
\Drupal\Core\Entity\EntityInterface $entity: The entity info from entity_get_info().
Return value
array An array of stylesheets to be used for this template.
1 call to RendererBase::addCss()
- ContentEntityRenderer::generateHtml in src/
Renderer/ ContentEntityRenderer.php - Generate the HTML for the PDF.
File
- src/
Renderer/ RendererBase.php, line 93
Class
- RendererBase
- The RendererBase class.
Namespace
Drupal\entity_print\RendererCode
protected function addCss($render, EntityInterface $entity) {
$theme = $this->themeHandler
->getDefault();
$theme_path = $this
->getThemePath($theme);
/** @var \Drupal\Core\Extension\InfoParser $parser */
$theme_info = $this->infoParser
->parse("{$theme_path}/{$theme}.info.yml");
// Parse out the CSS from the theme info.
if (isset($theme_info['entity_print'])) {
// See if we have the special "all" key which is added to every PDF.
if (isset($theme_info['entity_print']['all'])) {
$render['#attached']['library'][] = $theme_info['entity_print']['all'];
unset($theme_info['entity_print']['all']);
}
foreach ($theme_info['entity_print'] as $key => $value) {
// If the entity type doesn't match just skip.
if ($key !== $entity
->getEntityTypeId()) {
continue;
}
// Parse our css files per entity type and bundle.
foreach ($value as $css_bundle => $css) {
// If it's magic key "all" add it otherwise check the bundle.
if ($css_bundle === 'all' || $entity
->bundle() === $css_bundle) {
$render['#attached']['library'][] = $css;
}
}
}
}
return $render;
}