pdf title name-placeholder

This commit is contained in:
Yuri Kuznetsov
2021-08-07 09:39:57 +03:00
parent f3b74696c0
commit 387029c5a6
@@ -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 "<tcpdf method=\"{$function}\" params=\"{$paramsString}\" />";
}
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;
}
}