You are here

public function PrintBuilder::printHtml in Entity Print 8.2

Get a HTML version of the entity as used for the Print rendering.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The content entity to render.

bool $use_default_css: TRUE if you want the default CSS included, otherwise FALSE.

bool $optimize_css: TRUE if you the CSS should be compressed otherwise FALSE.

Return value

string The rendered HTML for the entity, the same as what is used for the Print.

Overrides PrintBuilderInterface::printHtml

File

src/PrintBuilder.php, line 70

Class

PrintBuilder
The print builder service.

Namespace

Drupal\entity_print

Code

public function printHtml(EntityInterface $entity, $use_default_css = TRUE, $optimize_css = TRUE) {
  $renderer = $this->rendererFactory
    ->create([
    $entity,
  ]);
  $content[] = $renderer
    ->render([
    $entity,
  ]);
  $render = [
    '#theme' => 'entity_print__' . $entity
      ->getEntityTypeId() . '__' . $entity
      ->bundle(),
    '#title' => $this
      ->t('View'),
    '#content' => $content,
    '#attached' => [],
  ];
  return $renderer
    ->generateHtml([
    $entity,
  ], $render, $use_default_css, $optimize_css);
}