From c64a39bad7a597ffd3a1c5773c6a691681f882f0 Mon Sep 17 00:00:00 2001 From: jekuaitk Date: Wed, 27 Mar 2024 13:26:53 +0100 Subject: [PATCH 01/11] #1039: Added base_url variable to maestro notification twig --- modules/os2forms_forloeb/src/MaestroHelper.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/modules/os2forms_forloeb/src/MaestroHelper.php b/modules/os2forms_forloeb/src/MaestroHelper.php index dfa65cae..c4d23b62 100644 --- a/modules/os2forms_forloeb/src/MaestroHelper.php +++ b/modules/os2forms_forloeb/src/MaestroHelper.php @@ -17,6 +17,7 @@ use Drupal\Core\Logger\LoggerChannelInterface; use Drupal\Core\Mail\MailManagerInterface; use Drupal\Core\Render\Markup; +use Drupal\Core\Site\Settings; use Drupal\Core\Url; use Drupal\entity_print\Plugin\EntityPrintPluginManagerInterface; use Drupal\maestro\Engine\MaestroEngine; @@ -615,6 +616,7 @@ private function renderHtml( 'action_label' => $actionLabel, 'webform_submission' => $submission, 'handler' => $this, + 'base_url' => Settings::get('base_url') ], ]; From 4d42d3bd88876558d05d48e384480d47ac56ae6a Mon Sep 17 00:00:00 2001 From: jekuaitk Date: Wed, 27 Mar 2024 13:29:00 +0100 Subject: [PATCH 02/11] #1039: Updated CHANGELOG --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e1764f85..c69e495e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,8 @@ 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 Maestro notification twig. ## [3.14.1] 2024-01-16 From 9186e26360bddee26535a224bacdf5729dd1e79e Mon Sep 17 00:00:00 2001 From: jekuaitk Date: Wed, 27 Mar 2024 13:42:51 +0100 Subject: [PATCH 03/11] #1039: Applied coding standards --- modules/os2forms_forloeb/src/MaestroHelper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/os2forms_forloeb/src/MaestroHelper.php b/modules/os2forms_forloeb/src/MaestroHelper.php index c4d23b62..1f6b12bb 100644 --- a/modules/os2forms_forloeb/src/MaestroHelper.php +++ b/modules/os2forms_forloeb/src/MaestroHelper.php @@ -616,7 +616,7 @@ private function renderHtml( 'action_label' => $actionLabel, 'webform_submission' => $submission, 'handler' => $this, - 'base_url' => Settings::get('base_url') + 'base_url' => Settings::get('base_url'), ], ]; From f96b25fe60a2b205b4cb644063adf5fde588da9f Mon Sep 17 00:00:00 2001 From: jekuaitk Date: Wed, 27 Mar 2024 14:22:00 +0100 Subject: [PATCH 04/11] #1039: Added base_url variable to twig variables --- CHANGELOG.md | 2 +- modules/os2forms_attachment/os2forms_attachment.module | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c69e495e..9a38c035 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,7 +15,7 @@ before starting to add changes. Use example [placed in the end of the page](#exa - [#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 Maestro notification twig. + Added `base_url` variable to twig templates. ## [3.14.1] 2024-01-16 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'); +} From f15c90eb0410396584082b20e9cc41734777e707 Mon Sep 17 00:00:00 2001 From: jekuaitk Date: Wed, 27 Mar 2024 16:04:11 +0100 Subject: [PATCH 05/11] #1039: Tokenize all notification html --- .../os2forms_forloeb/src/MaestroHelper.php | 29 ++++++++++++------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/modules/os2forms_forloeb/src/MaestroHelper.php b/modules/os2forms_forloeb/src/MaestroHelper.php index 1f6b12bb..feb8c791 100644 --- a/modules/os2forms_forloeb/src/MaestroHelper.php +++ b/modules/os2forms_forloeb/src/MaestroHelper.php @@ -506,7 +506,7 @@ public function renderNotification(WebformSubmissionInterface $submission, strin $processValue = static function (string $value) use ($taskUrl) { // Replace href="[maestro:task-url]" with href="«$taskUrl»". $value = preg_replace('/href\s*=\s*["\']\[maestro:task-url\]["\']/', sprintf('href="%s"', htmlspecialchars($taskUrl)), $value); - $value = preg_replace('/\[(maestro:[^]]+)\]/', '[\1]', $value); + $value = preg_replace('/\[(maestro:[^]]+)\]/', '(\1)', $value); return $value; }; @@ -523,12 +523,7 @@ public function renderNotification(WebformSubmissionInterface $submission, strin $content = $notificationSetting[MaestroNotificationHandler::NOTIFICATION_CONTENT]; if (isset($content['value'])) { - // Process tokens in content. - $content['value'] = $this->tokenManager->replace( - $processValue($content['value']), - $submission, - $maestroTokenData - ); + $content['value'] = $processValue($content['value']); } $actionLabel = $this->tokenManager->replace($notificationSetting[MaestroNotificationHandler::NOTIFICATION_ACTION_LABEL], $submission); @@ -539,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 */ @@ -584,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,7 +591,8 @@ private function renderHtml( array $content, string $taskUrl, string $actionLabel, - WebformSubmissionInterface $submission + WebformSubmissionInterface $submission, + array $maestroTokenData, ): string|MarkupInterface { $template = $this->config->get('templates')['notification_' . $type] ?? NULL; if (file_exists($template)) { @@ -620,7 +618,16 @@ private function renderHtml( ], ]; - return Markup::create(trim((string) $this->webformThemeManager->renderPlain($build))); + + $html = trim((string) $this->webformThemeManager->renderPlain($build)); + + $html = $this->tokenManager->replace( + $html, + $submission, + $maestroTokenData + ); + + return Markup::create($html); } /** From e5fc11a5f7eea6d28522c4ec1195a9f345c0555d Mon Sep 17 00:00:00 2001 From: jekuaitk Date: Wed, 27 Mar 2024 16:06:05 +0100 Subject: [PATCH 06/11] #1039: Applied coding standards --- modules/os2forms_forloeb/src/MaestroHelper.php | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/os2forms_forloeb/src/MaestroHelper.php b/modules/os2forms_forloeb/src/MaestroHelper.php index feb8c791..8f8e24a9 100644 --- a/modules/os2forms_forloeb/src/MaestroHelper.php +++ b/modules/os2forms_forloeb/src/MaestroHelper.php @@ -618,7 +618,6 @@ private function renderHtml( ], ]; - $html = trim((string) $this->webformThemeManager->renderPlain($build)); $html = $this->tokenManager->replace( From b815d6279dff3a3e6d564d9eab6b5265ee7b7ca1 Mon Sep 17 00:00:00 2001 From: jekuaitk Date: Tue, 2 Apr 2024 09:48:53 +0200 Subject: [PATCH 07/11] #1039: Cleanup --- CHANGELOG.md | 3 ++- modules/os2forms_attachment/README.md | 20 +++++++++++++++++++ modules/os2forms_forloeb/README.md | 18 ++++++++++++++++- .../os2forms_forloeb/src/MaestroHelper.php | 6 ++---- 4 files changed, 41 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a38c035..16547769 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,7 +15,8 @@ before starting to add changes. Use example [placed in the end of the page](#exa - [#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. + - Added `base_url` variable to twig templates. + - Tokenized all Maestro notification html. ## [3.14.1] 2024-01-16 diff --git a/modules/os2forms_attachment/README.md b/modules/os2forms_attachment/README.md index 09ff6cf1..3dfea56d 100644 --- a/modules/os2forms_attachment/README.md +++ b/modules/os2forms_attachment/README.md @@ -13,3 +13,23 @@ 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. + +For this reason the `base_url` variable has been added for use in templates. +Set it in `settings.local.php` + +```php +/** + * Base url. + * + * Used to specify full path to stylesheets in templates. + */ +$settings['base_url'] = 'http://nginx:8080'; +``` + +and use it in templates with `{{ base_url }}`. diff --git a/modules/os2forms_forloeb/README.md b/modules/os2forms_forloeb/README.md index 5d00e940..b7d0ed0a 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,19 @@ must be processed asynchronously. Specify the queue handling notification jobs. #### Templates Define templates for emails and digital post (PDF). + +With some setups it might be necessary to import stylesheets with a full path. + +For this reason the `base_url` variable has been added for use in templates. +Set it in `settings.local.php` + +```php +/** + * Base url. + * + * Used to specify full path to stylesheets in templates. + */ +$settings['base_url'] = 'http://nginx:8080'; +``` + +and use it in templates with `{{ base_url }}`. diff --git a/modules/os2forms_forloeb/src/MaestroHelper.php b/modules/os2forms_forloeb/src/MaestroHelper.php index 8f8e24a9..5adf6787 100644 --- a/modules/os2forms_forloeb/src/MaestroHelper.php +++ b/modules/os2forms_forloeb/src/MaestroHelper.php @@ -620,13 +620,11 @@ private function renderHtml( $html = trim((string) $this->webformThemeManager->renderPlain($build)); - $html = $this->tokenManager->replace( + return Markup::create($this->tokenManager->replace( $html, $submission, $maestroTokenData - ); - - return Markup::create($html); + )); } /** From b50d0f818e0f3656702036a7b59fe07b89327182 Mon Sep 17 00:00:00 2001 From: jekuaitk Date: Tue, 2 Apr 2024 09:50:59 +0200 Subject: [PATCH 08/11] #1039: Applied coding standards --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 16547769..36342345 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,8 +15,8 @@ before starting to add changes. Use example [placed in the end of the page](#exa - [#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. - - Tokenized all Maestro notification html. + - Added `base_url` variable to twig templates. + - Tokenized all Maestro notification html. ## [3.14.1] 2024-01-16 From 2cbaa9560aaef99090a8333723e85df2d49b6888 Mon Sep 17 00:00:00 2001 From: Jeppe Kuhlmann Andersen <78410897+jekuaitk@users.noreply.github.com> Date: Tue, 2 Apr 2024 10:16:56 +0200 Subject: [PATCH 09/11] Update CHANGELOG.md Co-authored-by: Mikkel Ricky --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 36342345..47db00b5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,7 +16,7 @@ before starting to add changes. Use example [placed in the end of the page](#exa Added digital post test command. - [#95](https://github.com/OS2Forms/os2forms/pull/95) - Added `base_url` variable to twig templates. - - Tokenized all Maestro notification html. + - Handled tokens in Maestro notification html. ## [3.14.1] 2024-01-16 From 6d0098df6a77ca609dd18b120adfdf40fccd938e Mon Sep 17 00:00:00 2001 From: Jeppe Kuhlmann Andersen <78410897+jekuaitk@users.noreply.github.com> Date: Tue, 2 Apr 2024 10:17:12 +0200 Subject: [PATCH 10/11] Update modules/os2forms_attachment/README.md Co-authored-by: Mikkel Ricky --- modules/os2forms_attachment/README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/os2forms_attachment/README.md b/modules/os2forms_attachment/README.md index 3dfea56d..092408c0 100644 --- a/modules/os2forms_attachment/README.md +++ b/modules/os2forms_attachment/README.md @@ -14,7 +14,6 @@ To specify headers/footers that will override the default ones on a global level 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 From a3d114625c570d2a39d96618ac633752c73db060 Mon Sep 17 00:00:00 2001 From: jekuaitk Date: Tue, 2 Apr 2024 10:26:52 +0200 Subject: [PATCH 11/11] #1039: Cleanup --- modules/os2forms_attachment/README.md | 17 +++-------------- modules/os2forms_forloeb/README.md | 15 +++++++++------ 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/modules/os2forms_attachment/README.md b/modules/os2forms_attachment/README.md index 092408c0..f732ad2f 100644 --- a/modules/os2forms_attachment/README.md +++ b/modules/os2forms_attachment/README.md @@ -17,18 +17,7 @@ To specify headers/footers that will override the default ones on a form level ( # Overwriting templates With some setups it might be necessary to overwrite templates -in order to access stylesheets. +in order to access stylesheets or images. -For this reason the `base_url` variable has been added for use in templates. -Set it in `settings.local.php` - -```php -/** - * Base url. - * - * Used to specify full path to stylesheets in templates. - */ -$settings['base_url'] = 'http://nginx:8080'; -``` - -and use it in templates with `{{ base_url }}`. +See [templates](modules/os2forms_forloeb/README.md#templates) +for more details on how to do this. diff --git a/modules/os2forms_forloeb/README.md b/modules/os2forms_forloeb/README.md index b7d0ed0a..7cf06186 100644 --- a/modules/os2forms_forloeb/README.md +++ b/modules/os2forms_forloeb/README.md @@ -45,18 +45,21 @@ must be processed asynchronously. Specify the queue handling notification jobs. Define templates for emails and digital post (PDF). -With some setups it might be necessary to import stylesheets with a full path. -For this reason the `base_url` variable has been added for use in templates. -Set it in `settings.local.php` +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 +