Documentation

PrintGuide extends ControllerBase
in package

Controller for generating and downloading PDF versions of guide nodes.

This controller supports transforming guide node content and its related entities into a formatted PDF document. It leverages Dompdf for PDF generation and includes functionality for processing various field types and media.

Table of Contents

Methods

bookDisplayForPDF()  : string
Formats and displays book information for inclusion in the PDF.
downloadGuide()  : RedirectResponse|Response
Generates a PDF for a given node of type 'guide'.
generatePdf()  : void
Generates and streams a PDF document from HTML content.
getFieldNameByMediaType()  : string
Helper method to determine the appropriate field name based on media type.
modifyHtmlContent()  : false|string
Modifies HTML content, converting image tags into clickable links.
prepareHtmlContent()  : array<string|int, mixed>|string|null
Prepares HTML content for PDF rendering, adjusting image paths.
processBox()  : string
Processes and formats box entities associated with a guide for PDF output.
processMediaItem()  : string
Processes media entities for inclusion in the PDF, adjusting links and formats.
processPage()  : string
Processes page entities associated with a guide for PDF output.

Methods

bookDisplayForPDF()

Formats and displays book information for inclusion in the PDF.

public bookDisplayForPDF(EntityInterface $entity[, bool $includeTitle = true ]) : string
Parameters
$entity : EntityInterface

The book entity.

$includeTitle : bool = true

Whether to include the book title in the output.

Return values
string

Formatted HTML content for the book.

downloadGuide()

Generates a PDF for a given node of type 'guide'.

public downloadGuide(NodeInterface $node) : RedirectResponse|Response
Parameters
$node : NodeInterface

The guide node entity.

Tags
throws
DOMException

Thrown if there's an error in processing HTML content.

throws
EntityMalformedException

Thrown if there's an issue with entity data.

Return values
RedirectResponse|Response

Redirects to the node page if the node is not of type 'guide', or initiates a PDF download response.

generatePdf()

Generates and streams a PDF document from HTML content.

protected generatePdf(string $html, string $title) : void
Parameters
$html : string

The HTML content to convert into a PDF.

$title : string

The title for the PDF document.

Tags
throws
DOMException

If there's an error during PDF generation.

getFieldNameByMediaType()

Helper method to determine the appropriate field name based on media type.

protected getFieldNameByMediaType(string $mediaType) : string
Parameters
$mediaType : string

The bundle of the media entity.

Return values
string

The field name associated with the media file.

modifyHtmlContent()

Modifies HTML content, converting image tags into clickable links.

protected modifyHtmlContent(string $htmlContent, string $baseUrl) : false|string
Parameters
$htmlContent : string

The original HTML content.

$baseUrl : string

The base URL of the site for absolute links.

Tags
throws
DOMException

If there's an error loading or saving HTML.

Return values
false|string

The modified HTML content.

prepareHtmlContent()

Prepares HTML content for PDF rendering, adjusting image paths.

protected prepareHtmlContent(string $htmlContent, string $baseUrl) : array<string|int, mixed>|string|null
Parameters
$htmlContent : string

The original HTML content.

$baseUrl : string

The base URL of the site for absolute links.

Return values
array<string|int, mixed>|string|null

The prepared HTML content.

processBox()

Processes and formats box entities associated with a guide for PDF output.

protected processBox( $box, string $baseUrl) : string
Parameters
$box :

The box entity to process.

$baseUrl : string

The base URL of the site for absolute links.

Tags
throws
DOMException

If there's an error in HTML content manipulation.

Return values
string

Formatted HTML content for the box.

processMediaItem()

Processes media entities for inclusion in the PDF, adjusting links and formats.

protected processMediaItem( $mediaItem, string $baseUrl) : string
Parameters
$mediaItem :

The media entity to process.

$baseUrl : string

The base URL of the site for absolute links.

Return values
string

Formatted HTML content for the media item.

processPage()

Processes page entities associated with a guide for PDF output.

protected processPage( $page, string $baseUrl) : string
Parameters
$page :

The page entity to process.

$baseUrl : string

The base URL of the site for absolute links.

Tags
throws
DOMException

If there's an error in HTML content manipulation.

Return values
string

Formatted HTML content for the page.


        
On this page

Search results