You are here

protected function HandlePdfController::buildFilename in FillPDF 5.0.x

Same name and namespace in other branches
  1. 8.4 src/Controller/HandlePdfController.php \Drupal\fillpdf\Controller\HandlePdfController::buildFilename()

Builds the filename of a populated PDF file.

Parameters

string $original: The original filename without tokens being replaced.

\Drupal\Core\Entity\EntityInterface[] $entities: An array of entities to be used for replacing tokens.

Return value

string The token-replaced filename.

1 call to HandlePdfController::buildFilename()
HandlePdfController::populatePdf in src/Controller/HandlePdfController.php
Populates PDF template from context.

File

src/Controller/HandlePdfController.php, line 169

Class

HandlePdfController
Class HandlePdfController.

Namespace

Drupal\fillpdf\Controller

Code

protected function buildFilename($original, array $entities) {

  // Replace tokens *before* sanitization.
  $original = (string) $this->tokenResolver
    ->replace($original, $entities, [
    'content' => 'text',
  ]);
  $output_name = str_replace(' ', '_', $original);
  $output_name = preg_replace('/\\.pdf$/i', '', $output_name);
  $output_name = preg_replace('/[^a-zA-Z0-9_.-]+/', '', $output_name) . '.pdf';
  return $output_name;
}