diff --git a/CHANGELOG.md b/CHANGELOG.md index 1f85ea20..663b043c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,9 @@ before starting to add changes. Use example [placed in the end of the page](#exa - Adding Lat and Long fetching to DataAddress - [#84](https://github.com/OS2Forms/os2forms/pull/84) Added digital post test command. +- [#95](https://github.com/OS2Forms/os2forms/pull/95) + - Added `base_url` variable to twig templates. + - Handled tokens in Maestro notification html. - [#92](https://github.com/OS2Forms/os2forms/pull/92) Allow denying address protected citizen from webform. - [#96](https://github.com/OS2Forms/os2forms/pull/96) diff --git a/modules/os2forms_attachment/README.md b/modules/os2forms_attachment/README.md index 09ff6cf1..f732ad2f 100644 --- a/modules/os2forms_attachment/README.md +++ b/modules/os2forms_attachment/README.md @@ -13,3 +13,11 @@ To add custom headers/footer ```admin/structure/webform/config/os2forms_attachme To specify headers/footers that will override the default ones on a global level (**Third party settings** -> **Entity print** section): ```admin/structure/webform/config``` To specify headers/footers that will override the default ones on a form level (**Third party settings** -> **Entity print** section): ```/admin/structure/webform/manage/[webform]/settings``` + +# Overwriting templates + +With some setups it might be necessary to overwrite templates +in order to access stylesheets or images. + +See [templates](modules/os2forms_forloeb/README.md#templates) +for more details on how to do this. diff --git a/modules/os2forms_attachment/os2forms_attachment.module b/modules/os2forms_attachment/os2forms_attachment.module index 9f8892c9..86f313a9 100644 --- a/modules/os2forms_attachment/os2forms_attachment.module +++ b/modules/os2forms_attachment/os2forms_attachment.module @@ -8,6 +8,7 @@ use Drupal\Core\Entity\Display\EntityViewDisplayInterface; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\Site\Settings; use Drupal\os2forms_attachment\Entity\AttachmentComponent; /** @@ -317,3 +318,12 @@ function os2forms_attachment_module_implements_alter(&$implementations, $hook) { } } + +/** + * Implements hook_preprocess(). + * + * Add 'base_url' variable to be used by templates. + */ +function os2forms_attachment_preprocess(&$vars) { + $vars['base_url'] = Settings::get('base_url'); +} diff --git a/modules/os2forms_forloeb/README.md b/modules/os2forms_forloeb/README.md index 5d00e940..7cf06186 100644 --- a/modules/os2forms_forloeb/README.md +++ b/modules/os2forms_forloeb/README.md @@ -19,7 +19,7 @@ You can also install the module by using Drush: Maestro 3.1 adds a `hook_webform_submission_form_alter` hook which we utilize to send assignment, reminder and escalation notifications by adding a *Maestro notification* handler to a form that spawns a Maestro workflow or assigns a -task. If the notification recipient is identified by an an email address, the +task. If the notification recipient is identified by an email address, the notification is sent as an email, and if the identifier is a Danish CPR number, the notifications is sent as digital post. @@ -44,3 +44,22 @@ must be processed asynchronously. Specify the queue handling notification jobs. #### Templates Define templates for emails and digital post (PDF). + + +To reference assets, e.g. stylesheet or images, in your templates, +you can use the `base_url` Twig variable to get the base URL: + +```html +tokenManager->replace( - $processValue($content['value']), - $submission, - $maestroTokenData - ); + $content['value'] = $processValue($content['value']); } $actionLabel = $this->tokenManager->replace($notificationSetting[MaestroNotificationHandler::NOTIFICATION_ACTION_LABEL], $submission); @@ -538,11 +534,11 @@ public function renderNotification(WebformSubmissionInterface $submission, strin switch ($contentType) { case 'email': - $content = $this->renderHtml($contentType, $subject, $content, $taskUrl, $actionLabel, $submission); + $content = $this->renderHtml($contentType, $subject, $content, $taskUrl, $actionLabel, $submission, $maestroTokenData); break; case 'pdf': - $pdfContent = $this->renderHtml($contentType, $subject, $content, $taskUrl, $actionLabel, $submission); + $pdfContent = $this->renderHtml($contentType, $subject, $content, $taskUrl, $actionLabel, $submission, $maestroTokenData); // Get dompdf plugin from entity_print module. /** @var \Drupal\entity_print\Plugin\EntityPrint\PrintEngine\PdfEngineBase $printer */ @@ -583,6 +579,8 @@ public function renderNotification(WebformSubmissionInterface $submission, strin * The action label. * @param \Drupal\webform\WebformSubmissionInterface $submission * The webform submission. + * @param array $maestroTokenData + * The Maestro token data. * * @return string|MarkupInterface * The rendered content. @@ -594,6 +592,7 @@ private function renderHtml( string $taskUrl, string $actionLabel, WebformSubmissionInterface $submission, + array $maestroTokenData, ): string|MarkupInterface { $template = $this->config->get('templates')['notification_' . $type] ?? NULL; if (file_exists($template)) { @@ -615,10 +614,17 @@ private function renderHtml( 'action_label' => $actionLabel, 'webform_submission' => $submission, 'handler' => $this, + 'base_url' => Settings::get('base_url'), ], ]; - return Markup::create(trim((string) $this->webformThemeManager->renderPlain($build))); + $html = trim((string) $this->webformThemeManager->renderPlain($build)); + + return Markup::create($this->tokenManager->replace( + $html, + $submission, + $maestroTokenData + )); } /**