1818 */
1919class Os2formsAttachmentPrintBuilder extends PrintBuilder {
2020
21+ public const SIGNATURE_POSITION_FOOTER = 'footer ' ;
22+ public const SIGNATURE_POSITION_HEADER = 'header ' ;
23+ public const SIGNATURE_POSITION_AFTER_CONTENT = 'after_content ' ;
24+ public const SIGNATURE_POSITION_BEFORE_CONTENT = 'before_content ' ;
25+
2126 /**
2227 * {@inheritdoc}
2328 */
@@ -44,16 +49,16 @@ public function printHtml(EntityInterface $entity, $use_default_css = TRUE, $opt
4449 /**
4550 * Modified version of the original savePrintable() function.
4651 *
47- * The only difference is modified call to prepareRenderer with digitalPost
48- * flag TRUE .
52+ * The only difference is modified call to prepareRenderer with a
53+ * signature position parameter .
4954 *
5055 * @see PrintBuilder::savePrintable()
5156 *
5257 * @return string
5358 * FALSE or the URI to the file. E.g. public://my-file.pdf.
5459 */
55- public function savePrintableDigitalSignature (array $ entities , PrintEngineInterface $ print_engine , $ scheme = 'public ' , $ filename = FALSE , $ use_default_css = TRUE ) {
56- $ renderer = $ this ->prepareRenderer ($ entities , $ print_engine , $ use_default_css , TRUE );
60+ public function savePrintableDigitalSignature (array $ entities , PrintEngineInterface $ print_engine , $ scheme = 'public ' , $ filename = FALSE , $ use_default_css = TRUE , string $ signaturePosition = self :: SIGNATURE_POSITION_AFTER_CONTENT ) {
61+ $ renderer = $ this ->prepareRenderer ($ entities , $ print_engine , $ use_default_css , $ signaturePosition );
5762
5863 // Allow other modules to alter the generated Print object.
5964 $ this ->dispatcher ->dispatch (new PreSendPrintEvent ($ print_engine , $ entities ), PrintEvents::PRE_SEND );
@@ -82,15 +87,16 @@ public function savePrintableDigitalSignature(array $entities, PrintEngineInterf
8287 * The print engine.
8388 * @param bool $use_default_css
8489 * TRUE if we want the default CSS included.
85- * @param bool $digitalSignature
86- * If the digital signature message needs to be added.
90+ * @param string $signaturePosition
91+ * The position for the digital signature validation text. Empty string
92+ * means no signature. Use the SIGNATURE_POSITION_* class constants.
8793 *
8894 * @return \Drupal\entity_print\Renderer\RendererInterface
8995 * A print renderer.
9096 *
9197 * @see PrintBuilder::prepareRenderer
9298 */
93- protected function prepareRenderer (array $ entities , PrintEngineInterface $ print_engine , $ use_default_css , $ digitalSignature = FALSE ) {
99+ protected function prepareRenderer (array $ entities , PrintEngineInterface $ print_engine , $ use_default_css , string $ signaturePosition = '' ) {
94100 if (empty ($ entities )) {
95101 throw new \InvalidArgumentException ('You must pass at least 1 entity ' );
96102 }
@@ -106,12 +112,30 @@ protected function prepareRenderer(array $entities, PrintEngineInterface $print_
106112 '#attached ' => [],
107113 ];
108114
109- // Adding hardcoded negative margin to avoid margins in <fieldset> <legend>
110- // structure. That margin is automatically added in PDF and PDF only.
111115 $ generatedHtml = (string ) $ renderer ->generateHtml ($ entities , $ render , $ use_default_css , TRUE );
112- $ generatedHtml .= "<style>fieldset legend {margin-left: -12px;}</style> " ;
113- if ($ digitalSignature ) {
114- $ generatedHtml .= $ this ->t ('You can validate the signature on this PDF file via validering.nemlog-in.dk. ' );
116+
117+ // Place signature according to the passed parameter.
118+ if ($ signaturePosition ) {
119+ $ signatureHtml = '<div class="validate-signature-element"><p> ' . $ this ->t ('You can validate the signature on this PDF file via validering.nemlog-in.dk. ' ) . '</p></div> ' ;
120+
121+ switch ($ signaturePosition ) {
122+ case self ::SIGNATURE_POSITION_HEADER :
123+ $ generatedHtml = str_replace ('</header> ' , $ signatureHtml . '</header> ' , $ generatedHtml );
124+ break ;
125+
126+ case self ::SIGNATURE_POSITION_BEFORE_CONTENT :
127+ $ generatedHtml = str_replace ('<div class="page"> ' , '<div class="page"> ' . $ signatureHtml , $ generatedHtml );
128+ break ;
129+
130+ case self ::SIGNATURE_POSITION_FOOTER :
131+ $ generatedHtml = str_replace ('</footer> ' , $ signatureHtml . '</footer> ' , $ generatedHtml );
132+ break ;
133+
134+ case self ::SIGNATURE_POSITION_AFTER_CONTENT :
135+ default :
136+ $ generatedHtml = str_replace ('</body> ' , $ signatureHtml . '</body> ' , $ generatedHtml );
137+ break ;
138+ }
115139 }
116140
117141 $ print_engine ->addPage ($ generatedHtml );
0 commit comments