You are here

protected function EntityPrintPdfBuilder::generateFilename in Entity Print 8

Generate a filename from the entity.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The content entity to generate the filename.

bool $with_extension: Allow us to exclude the PDF file extension when generating the filename.

Return value

string The cleaned filename from the entity label.

2 calls to EntityPrintPdfBuilder::generateFilename()
EntityPrintPdfBuilder::generateMultiFilename in src/EntityPrintPdfBuilder.php
EntityPrintPdfBuilder::getEntityRenderedAsPdf in src/EntityPrintPdfBuilder.php
Render any content entity as a PDF.

File

src/EntityPrintPdfBuilder.php, line 92

Class

EntityPrintPdfBuilder

Namespace

Drupal\entity_print

Code

protected function generateFilename(EntityInterface $entity, $with_extension = TRUE) {
  $filename = preg_replace("/[^A-Za-z0-9 ]/", '', $entity
    ->label());

  // If for some bizarre reason there isn't a valid character in the entity
  // title or the entity doesn't provide a label then we use the entity type.
  if (!$filename) {
    $filename = $entity
      ->getEntityTypeId();
  }
  return $with_extension ? $filename . '.pdf' : $filename;
}