diff --git a/CHANGELOG.md b/CHANGELOG.md index f6f3e756..14bd0633 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,9 @@ before starting to add changes. Use example [placed in the end of the page](#exa ## [Unreleased] +- [PR-306](https://github.com/OS2Forms/os2forms/pull/306) + Made digital signature text placement configurable. + ## [5.0.0] 2025-11-18 - [PR-192](https://github.com/OS2Forms/os2forms/pull/192) diff --git a/modules/os2forms_attachment/src/Element/AttachmentElement.php b/modules/os2forms_attachment/src/Element/AttachmentElement.php index cdf3ae44..bbc33f0b 100644 --- a/modules/os2forms_attachment/src/Element/AttachmentElement.php +++ b/modules/os2forms_attachment/src/Element/AttachmentElement.php @@ -2,6 +2,7 @@ namespace Drupal\os2forms_attachment\Element; +use Drupal\os2forms_attachment\Os2formsAttachmentPrintBuilder; use Drupal\webform\Entity\WebformSubmission; use Drupal\webform\WebformSubmissionInterface; use Drupal\webform_attachment\Element\WebformAttachmentBase; @@ -21,6 +22,7 @@ public function getInfo() { '#view_mode' => 'html', '#export_type' => 'pdf', '#digital_signature' => FALSE, + '#digital_signature_position' => Os2formsAttachmentPrintBuilder::SIGNATURE_POSITION_AFTER_CONTENT, '#template' => '', ]; } @@ -77,7 +79,8 @@ public static function getFileContent(array $element, WebformSubmissionInterface // Adding digital signature. if (isset($element['#digital_signature']) && $element['#digital_signature']) { - $file_path = $print_builder->savePrintableDigitalSignature([$webform_submission], $print_engine, $scheme, $file_name); + $signaturePosition = $element['#digital_signature_position'] ?? Os2formsAttachmentPrintBuilder::SIGNATURE_POSITION_AFTER_CONTENT; + $file_path = $print_builder->savePrintableDigitalSignature([$webform_submission], $print_engine, $scheme, $file_name, TRUE, $signaturePosition); } else { $file_path = $print_builder->savePrintable([$webform_submission], $print_engine, $scheme, $file_name); diff --git a/modules/os2forms_attachment/src/Os2formsAttachmentPrintBuilder.php b/modules/os2forms_attachment/src/Os2formsAttachmentPrintBuilder.php index 1f8a9f38..c72f098c 100644 --- a/modules/os2forms_attachment/src/Os2formsAttachmentPrintBuilder.php +++ b/modules/os2forms_attachment/src/Os2formsAttachmentPrintBuilder.php @@ -18,6 +18,11 @@ */ class Os2formsAttachmentPrintBuilder extends PrintBuilder { + public const SIGNATURE_POSITION_FOOTER = 'footer'; + public const SIGNATURE_POSITION_HEADER = 'header'; + public const SIGNATURE_POSITION_AFTER_CONTENT = 'after_content'; + public const SIGNATURE_POSITION_BEFORE_CONTENT = 'before_content'; + /** * {@inheritdoc} */ @@ -44,16 +49,16 @@ public function printHtml(EntityInterface $entity, $use_default_css = TRUE, $opt /** * Modified version of the original savePrintable() function. * - * The only difference is modified call to prepareRenderer with digitalPost - * flag TRUE. + * The only difference is modified call to prepareRenderer with a + * signature position parameter. * * @see PrintBuilder::savePrintable() * * @return string * FALSE or the URI to the file. E.g. public://my-file.pdf. */ - public function savePrintableDigitalSignature(array $entities, PrintEngineInterface $print_engine, $scheme = 'public', $filename = FALSE, $use_default_css = TRUE) { - $renderer = $this->prepareRenderer($entities, $print_engine, $use_default_css, TRUE); + public function savePrintableDigitalSignature(array $entities, PrintEngineInterface $print_engine, $scheme = 'public', $filename = FALSE, $use_default_css = TRUE, string $signaturePosition = self::SIGNATURE_POSITION_AFTER_CONTENT) { + $renderer = $this->prepareRenderer($entities, $print_engine, $use_default_css, $signaturePosition); // Allow other modules to alter the generated Print object. $this->dispatcher->dispatch(new PreSendPrintEvent($print_engine, $entities), PrintEvents::PRE_SEND); @@ -82,15 +87,16 @@ public function savePrintableDigitalSignature(array $entities, PrintEngineInterf * The print engine. * @param bool $use_default_css * TRUE if we want the default CSS included. - * @param bool $digitalSignature - * If the digital signature message needs to be added. + * @param string $signaturePosition + * The position for the digital signature validation text. Empty string + * means no signature. Use the SIGNATURE_POSITION_* class constants. * * @return \Drupal\entity_print\Renderer\RendererInterface * A print renderer. * * @see PrintBuilder::prepareRenderer */ - protected function prepareRenderer(array $entities, PrintEngineInterface $print_engine, $use_default_css, $digitalSignature = FALSE) { + protected function prepareRenderer(array $entities, PrintEngineInterface $print_engine, $use_default_css, string $signaturePosition = '') { if (empty($entities)) { throw new \InvalidArgumentException('You must pass at least 1 entity'); } @@ -106,12 +112,30 @@ protected function prepareRenderer(array $entities, PrintEngineInterface $print_ '#attached' => [], ]; - // Adding hardcoded negative margin to avoid margins in