You are here

protected function ContentEntityRenderer::generateHtml in Entity Print 8

Generate the HTML for the PDF.

Parameters

array $render: The renderable array for our Entity Print theme hook.

array $entities: An array of entities that we're rendering.

bool $use_default_css: TRUE if we're including the default CSS otherwise FALSE.

bool $optimize_css: TRUE if we want to compress the CSS otherwise FALSE.

Return value

string The HTML rendered string.

2 calls to ContentEntityRenderer::generateHtml()
ContentEntityRenderer::getHtml in src/Renderer/ContentEntityRenderer.php
Generate the HTML for our entity.
ContentEntityRenderer::getHtmlMultiple in src/Renderer/ContentEntityRenderer.php
Generate the HTML for our entity.

File

src/Renderer/ContentEntityRenderer.php, line 80

Class

ContentEntityRenderer

Namespace

Drupal\entity_print\Renderer

Code

protected function generateHtml(array $render, array $entities, $use_default_css, $optimize_css) {

  // Inject some generic CSS across all templates.
  if ($use_default_css) {
    $render['#attached']['library'][] = 'entity_print/default';
  }
  foreach ($entities as $entity) {

    // Inject CSS from the theme info files and then render the CSS.
    $render = $this
      ->addCss($render, $entity);
  }
  $this->dispatcher
    ->dispatch(PdfEvents::CSS_ALTER, new PdfCssAlterEvent($render, $entities));
  $css_assets = $this->assetResolver
    ->getCssAssets(AttachedAssets::createFromRenderArray($render), $optimize_css);
  $rendered_css = $this->cssRenderer
    ->render($css_assets);
  $render['#entity_print_css'] = $this->renderer
    ->render($rendered_css);
  $html = (string) $this->renderer
    ->render($render);

  // Allow other modules to alter the generated HTML.
  $this->dispatcher
    ->dispatch(PdfEvents::POST_RENDER, new PdfHtmlAlterEvent($html, $entities));
  return $html;
}