From 387029c5a69b08d6c1d64ce30f8f9a1efe6a580f Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Sat, 7 Aug 2021 09:39:57 +0300 Subject: [PATCH] pdf title name-placeholder --- .../Espo/Tools/Pdf/Tcpdf/EntityProcessor.php | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/application/Espo/Tools/Pdf/Tcpdf/EntityProcessor.php b/application/Espo/Tools/Pdf/Tcpdf/EntityProcessor.php index 1393272cc5..cf20ac9cb8 100644 --- a/application/Espo/Tools/Pdf/Tcpdf/EntityProcessor.php +++ b/application/Espo/Tools/Pdf/Tcpdf/EntityProcessor.php @@ -73,8 +73,9 @@ class EntityProcessor } if ($template->hasTitle()) { - // @todo Support placeholders. - $pdf->SetTitle($template->getTitle()); + $title = $this->replacePlaceholders($template->getTitle(), $entity); + + $pdf->SetTitle($title); } $pdf->setFont($fontFace, '', $this->fontSize, '', true); @@ -230,4 +231,19 @@ class EntityProcessor return ""; } + + private function replacePlaceholders(string $string, Entity $entity): string + { + $newString = $string; + + $attributeList = ['name']; + + foreach ($attributeList as $attribute) { + $value = (string) ($entity->get($attribute) ?? ''); + + $newString = str_replace('{$' . $attribute . '}', $value, $newString); + } + + return $newString; + } }