From 9ac31c31ce9832d96de0eeda6f424f9bbbb6a73f Mon Sep 17 00:00:00 2001 From: Stanislav Kutasevits Date: Tue, 20 Jun 2023 15:54:43 +0300 Subject: [PATCH 01/14] Fixing PDF attachment styles --- modules/os2forms_attachment/os2forms_attachment.module | 6 +++--- .../src/Os2formsAttachmentPrintBuilder.php | 7 ++++++- .../os2forms-attachment--webform-submission.html.twig | 9 +++++++++ 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/modules/os2forms_attachment/os2forms_attachment.module b/modules/os2forms_attachment/os2forms_attachment.module index c122ba93..9f8892c9 100644 --- a/modules/os2forms_attachment/os2forms_attachment.module +++ b/modules/os2forms_attachment/os2forms_attachment.module @@ -198,7 +198,7 @@ function _os2forms_attachment_print_form_add_template_override(array &$element, '#options' => $header_options, '#description' => t('Select default header that will be used on all forms (use standard for no override)'), '#empty_option' => t('Use standard'), - '#default_value' => $template_settings['os2forms_header'] ?? '', + '#default_value' => $template_settings['os2form_header'] ?? '', '#weight' => -1, ]; @@ -208,7 +208,7 @@ function _os2forms_attachment_print_form_add_template_override(array &$element, '#options' => $colophon_options, '#description' => t('Select default colophon that will be used on all forms (use standard for no override)'), '#empty_option' => t('Use standard'), - '#default_value' => $template_settings['os2forms_colophon'] ?? '', + '#default_value' => $template_settings['os2form_colophon'] ?? '', '#weight' => -1, ]; @@ -218,7 +218,7 @@ function _os2forms_attachment_print_form_add_template_override(array &$element, '#options' => $footer_options, '#description' => t('Select default footer that will be used on all forms (use standard for no override)'), '#empty_option' => t('Use standard'), - '#default_value' => $template_settings['os2forms_footer'] ?? '', + '#default_value' => $template_settings['os2form_footer'] ?? '', '#weight' => 0, ]; diff --git a/modules/os2forms_attachment/src/Os2formsAttachmentPrintBuilder.php b/modules/os2forms_attachment/src/Os2formsAttachmentPrintBuilder.php index 4ae09ee2..67a0c99a 100644 --- a/modules/os2forms_attachment/src/Os2formsAttachmentPrintBuilder.php +++ b/modules/os2forms_attachment/src/Os2formsAttachmentPrintBuilder.php @@ -46,7 +46,12 @@ protected function prepareRenderer(array $entities, PrintEngineInterface $print_ '#attached' => [], ]; - $print_engine->addPage($renderer->generateHtml($entities, $render, $use_default_css, TRUE)); + // Adding hardcoded negative margin to avoid margins in
+ // structure. That margin is automatically added in PDF and PDF only. + $generatedHtml = (string) $renderer->generateHtml($entities, $render, $use_default_css, TRUE); + $generatedHtml .= ""; + + $print_engine->addPage($generatedHtml); return $renderer; } diff --git a/modules/os2forms_attachment/templates/os2forms-attachment--webform-submission.html.twig b/modules/os2forms_attachment/templates/os2forms-attachment--webform-submission.html.twig index 817de37c..17917103 100644 --- a/modules/os2forms_attachment/templates/os2forms-attachment--webform-submission.html.twig +++ b/modules/os2forms_attachment/templates/os2forms-attachment--webform-submission.html.twig @@ -68,6 +68,15 @@ .table { width: 100%; } + + legend, summary, .details-wrapper, fieldset { + padding: 0; + } + + fieldset { + margin: 0; + border: 0; + } From eb2a00300cbb9dab6395fc90a821719a85d9880f Mon Sep 17 00:00:00 2001 From: Stanislav Kutasevits Date: Thu, 22 Jun 2023 10:41:32 +0300 Subject: [PATCH 02/14] Preparing 3.7.0 --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index dcd7baae..7ba1a9f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,10 @@ before starting to add changes. Use example [placed in the end of the page](#exa ## [Unreleased] +## [3.7.0] 2023-06-22 + +- [S2FRMS-18] - Fixing PDF styles + ## [3.6.0] 2023-06-07 - [OSF-25] added modules/os2forms_forloeb From 2902d0f3953ea06a67700600ce17f4e61a4f3336 Mon Sep 17 00:00:00 2001 From: Stanislav Kutasevits Date: Thu, 22 Jun 2023 10:55:41 +0300 Subject: [PATCH 03/14] Fixing PHPCS - Use statements should be sorted alphabetically --- .../src/Form/AttachmentComponentDeleteForm.php | 2 +- .../src/Form/AttachmentComponentForm.php | 2 +- modules/os2forms_consent/os2forms_consent.module | 2 +- .../src/Element/WebformAttachmentConsentXml.php | 2 +- modules/os2forms_forloeb/os2forms_forloeb.module | 8 ++++---- .../src/Controller/ForloebTaskConsoleController.php | 2 +- .../Plugin/EngineTasks/MaestroSelectContentTask.php | 10 +++++----- .../Plugin/EngineTasks/MaestroWebformInheritTask.php | 8 ++++---- .../Plugin/EngineTasks/MaestroWebformMultipleTask.php | 6 +++--- .../src/EventSubscriber/NemloginRedirectSubscriber.php | 6 +++--- .../os2forms_permissions_by_term.module | 2 +- modules/os2forms_sbsys/os2forms_sbsys.module | 2 +- .../src/Element/WebformAttachmentSbsysXml.php | 2 +- os2forms.module | 4 ++-- src/Plugin/WebformHandler/SaveToFileWebformHandler.php | 2 +- 15 files changed, 30 insertions(+), 30 deletions(-) diff --git a/modules/os2forms_attachment/src/Form/AttachmentComponentDeleteForm.php b/modules/os2forms_attachment/src/Form/AttachmentComponentDeleteForm.php index e3db6d10..123dc3e1 100644 --- a/modules/os2forms_attachment/src/Form/AttachmentComponentDeleteForm.php +++ b/modules/os2forms_attachment/src/Form/AttachmentComponentDeleteForm.php @@ -3,8 +3,8 @@ namespace Drupal\os2forms_attachment\Form; use Drupal\Core\Entity\EntityConfirmFormBase; -use Drupal\Core\Url; use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\Url; /** * Class AttachmentComponentDeleteForm. diff --git a/modules/os2forms_attachment/src/Form/AttachmentComponentForm.php b/modules/os2forms_attachment/src/Form/AttachmentComponentForm.php index b75010a7..05dd93a6 100644 --- a/modules/os2forms_attachment/src/Form/AttachmentComponentForm.php +++ b/modules/os2forms_attachment/src/Form/AttachmentComponentForm.php @@ -6,8 +6,8 @@ use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Session\AccountInterface; -use Symfony\Component\DependencyInjection\ContainerInterface; use Drupal\webform\WebformTokenManagerInterface; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * Form handler for the Attachment component add and edit forms. diff --git a/modules/os2forms_consent/os2forms_consent.module b/modules/os2forms_consent/os2forms_consent.module index d48a5050..71bcdd69 100644 --- a/modules/os2forms_consent/os2forms_consent.module +++ b/modules/os2forms_consent/os2forms_consent.module @@ -5,8 +5,8 @@ * OS2Forms Consent functionality module. */ -use Drupal\migrate\Plugin\MigrationInterface; use Drupal\migrate\Plugin\MigrateSourceInterface; +use Drupal\migrate\Plugin\MigrationInterface; use Drupal\migrate\Row; use Symfony\Component\Yaml\Yaml; diff --git a/modules/os2forms_consent/src/Element/WebformAttachmentConsentXml.php b/modules/os2forms_consent/src/Element/WebformAttachmentConsentXml.php index 43344aa2..9f7eaa6f 100644 --- a/modules/os2forms_consent/src/Element/WebformAttachmentConsentXml.php +++ b/modules/os2forms_consent/src/Element/WebformAttachmentConsentXml.php @@ -2,9 +2,9 @@ namespace Drupal\os2forms_consent\Element; -use Drupal\webform\WebformSubmissionInterface; use Drupal\os2forms\Element\WebformAttachmentXml; use Drupal\os2forms_consent\Plugin\WebformElement\WebformAttachmentConsentXml as WebformElementAttachmentConsentXml; +use Drupal\webform\WebformSubmissionInterface; /** * Provides a 'webform_attachment_os2forms_consent_xml' element. diff --git a/modules/os2forms_forloeb/os2forms_forloeb.module b/modules/os2forms_forloeb/os2forms_forloeb.module index 1d70c116..4c5fac0d 100644 --- a/modules/os2forms_forloeb/os2forms_forloeb.module +++ b/modules/os2forms_forloeb/os2forms_forloeb.module @@ -5,17 +5,17 @@ * Install, update and uninstall functions for the os2forms_forloeb. */ -use Drupal\Core\Session\AccountInterface; -use Drupal\Core\Entity\EntityInterface; -use Drupal\webform\WebformInterface; use Drupal\Core\Access\AccessResult; +use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Render\BubbleableMetadata; +use Drupal\Core\Session\AccountInterface; use Drupal\Core\Url; use Drupal\maestro\Engine\MaestroEngine; use Drupal\os2forms_forloeb\Plugin\EngineTasks\MaestroWebformInheritTask; -use Drupal\webform\Entity\WebformSubmission; use Drupal\user\Entity\User; +use Drupal\webform\Entity\WebformSubmission; +use Drupal\webform\WebformInterface; use Drupal\webform\WebformSubmissionInterface; /** diff --git a/modules/os2forms_forloeb/src/Controller/ForloebTaskConsoleController.php b/modules/os2forms_forloeb/src/Controller/ForloebTaskConsoleController.php index 5866b48c..8f2e95b0 100644 --- a/modules/os2forms_forloeb/src/Controller/ForloebTaskConsoleController.php +++ b/modules/os2forms_forloeb/src/Controller/ForloebTaskConsoleController.php @@ -5,12 +5,12 @@ use Drupal\Component\Utility\UrlHelper; use Drupal\Core\Controller\ControllerBase; use Drupal\Core\Entity\EntityTypeManagerInterface; +use Drupal\Core\StringTranslation\PluralTranslatableMarkup; use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\Url; use Drupal\maestro\Engine\MaestroEngine; use Drupal\maestro\Utility\TaskHandler; use Drupal\os2forms_forloeb\ForloebTaskConsole; -use Drupal\Core\StringTranslation\PluralTranslatableMarkup; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\RequestStack; diff --git a/modules/os2forms_forloeb/src/Plugin/EngineTasks/MaestroSelectContentTask.php b/modules/os2forms_forloeb/src/Plugin/EngineTasks/MaestroSelectContentTask.php index e2affa3e..64141120 100644 --- a/modules/os2forms_forloeb/src/Plugin/EngineTasks/MaestroSelectContentTask.php +++ b/modules/os2forms_forloeb/src/Plugin/EngineTasks/MaestroSelectContentTask.php @@ -2,15 +2,15 @@ namespace Drupal\os2forms_forloeb\Plugin\EngineTasks; -use Drupal\node\Entity\Node; -use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Form\FormState; +use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Plugin\PluginBase; -use Drupal\maestro\MaestroTaskTrait; +use Drupal\Core\Routing\TrustedRedirectResponse; +use Drupal\maestro\Engine\MaestroEngine; use Drupal\maestro\Form\MaestroExecuteInteractive; use Drupal\maestro\MaestroEngineTaskInterface; -use Drupal\maestro\Engine\MaestroEngine; -use Drupal\Core\Routing\TrustedRedirectResponse; +use Drupal\maestro\MaestroTaskTrait; +use Drupal\node\Entity\Node; /** * Maestro Select a Content Item. diff --git a/modules/os2forms_forloeb/src/Plugin/EngineTasks/MaestroWebformInheritTask.php b/modules/os2forms_forloeb/src/Plugin/EngineTasks/MaestroWebformInheritTask.php index 5d6642a9..b33bf4b3 100644 --- a/modules/os2forms_forloeb/src/Plugin/EngineTasks/MaestroWebformInheritTask.php +++ b/modules/os2forms_forloeb/src/Plugin/EngineTasks/MaestroWebformInheritTask.php @@ -2,13 +2,13 @@ namespace Drupal\os2forms_forloeb\Plugin\EngineTasks; +use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Url; +use Drupal\maestro\Engine\MaestroEngine; +use Drupal\maestro\Form\MaestroExecuteInteractive; +use Drupal\maestro_webform\Plugin\EngineTasks\MaestroWebformTask; use Drupal\webform\Entity\WebformSubmission; use Drupal\webform\WebformSubmissionForm; -use Drupal\maestro_webform\Plugin\EngineTasks\MaestroWebformTask; -use Drupal\maestro\Form\MaestroExecuteInteractive; -use Drupal\maestro\Engine\MaestroEngine; -use Drupal\Core\Form\FormStateInterface; use Drupal\webform\WebformSubmissionInterface; use Symfony\Component\HttpFoundation\RedirectResponse; diff --git a/modules/os2forms_forloeb/src/Plugin/EngineTasks/MaestroWebformMultipleTask.php b/modules/os2forms_forloeb/src/Plugin/EngineTasks/MaestroWebformMultipleTask.php index 6c33d25c..22c26a71 100644 --- a/modules/os2forms_forloeb/src/Plugin/EngineTasks/MaestroWebformMultipleTask.php +++ b/modules/os2forms_forloeb/src/Plugin/EngineTasks/MaestroWebformMultipleTask.php @@ -2,11 +2,11 @@ namespace Drupal\os2forms_forloeb\Plugin\EngineTasks; +use Drupal\maestro\Engine\MaestroEngine; +use Drupal\maestro\Form\MaestroExecuteInteractive; +use Drupal\maestro_webform\Plugin\EngineTasks\MaestroWebformTask; use Drupal\webform\Entity\WebformSubmission; use Drupal\webform\WebformSubmissionForm; -use Drupal\maestro_webform\Plugin\EngineTasks\MaestroWebformTask; -use Drupal\maestro\Form\MaestroExecuteInteractive; -use Drupal\maestro\Engine\MaestroEngine; /** * Maestro Webform Task Plugin for Multiple Submissions. diff --git a/modules/os2forms_nemid/src/EventSubscriber/NemloginRedirectSubscriber.php b/modules/os2forms_nemid/src/EventSubscriber/NemloginRedirectSubscriber.php index 22cc78df..107cc319 100644 --- a/modules/os2forms_nemid/src/EventSubscriber/NemloginRedirectSubscriber.php +++ b/modules/os2forms_nemid/src/EventSubscriber/NemloginRedirectSubscriber.php @@ -9,13 +9,13 @@ use Drupal\Core\Session\AccountInterface; use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\Url; -use Drupal\os2web_nemlogin\Service\AuthProviderService; use Drupal\os2forms_nemid\Form\SettingsForm; +use Drupal\os2web_nemlogin\Service\AuthProviderService; use Drupal\webform\Entity\Webform; +use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\HttpFoundation\RedirectResponse; -use Symfony\Component\HttpKernel\KernelEvents; use Symfony\Component\HttpKernel\Event\GetResponseEvent; -use Symfony\Component\EventDispatcher\EventSubscriberInterface; +use Symfony\Component\HttpKernel\KernelEvents; /** * Event subscriber subscribing to KernelEvents::REQUEST. diff --git a/modules/os2forms_permissions_by_term/os2forms_permissions_by_term.module b/modules/os2forms_permissions_by_term/os2forms_permissions_by_term.module index d63be5f6..79185ac9 100644 --- a/modules/os2forms_permissions_by_term/os2forms_permissions_by_term.module +++ b/modules/os2forms_permissions_by_term/os2forms_permissions_by_term.module @@ -7,11 +7,11 @@ use Drupal\Core\Config\Entity\ConfigEntityInterface; use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\Session\AccountInterface; use Drupal\node\NodeInterface; use Drupal\views\Plugin\views\query\QueryPluginBase; use Drupal\views\ViewExecutable; use Drupal\webform\WebformInterface; -use Drupal\Core\Session\AccountInterface; /** * Implements hook_module_implements_alter(). diff --git a/modules/os2forms_sbsys/os2forms_sbsys.module b/modules/os2forms_sbsys/os2forms_sbsys.module index e2a66bd8..6c161633 100644 --- a/modules/os2forms_sbsys/os2forms_sbsys.module +++ b/modules/os2forms_sbsys/os2forms_sbsys.module @@ -5,8 +5,8 @@ * OS2Forms SBSYS functionality module. */ -use Drupal\migrate\Plugin\MigrationInterface; use Drupal\migrate\Plugin\MigrateSourceInterface; +use Drupal\migrate\Plugin\MigrationInterface; use Drupal\migrate\Row; use Symfony\Component\Yaml\Yaml; diff --git a/modules/os2forms_sbsys/src/Element/WebformAttachmentSbsysXml.php b/modules/os2forms_sbsys/src/Element/WebformAttachmentSbsysXml.php index 3cf707f2..95279765 100644 --- a/modules/os2forms_sbsys/src/Element/WebformAttachmentSbsysXml.php +++ b/modules/os2forms_sbsys/src/Element/WebformAttachmentSbsysXml.php @@ -2,9 +2,9 @@ namespace Drupal\os2forms_sbsys\Element; -use Drupal\webform\WebformSubmissionInterface; use Drupal\os2forms\Element\WebformAttachmentXml; use Drupal\os2forms_sbsys\Plugin\WebformElement\WebformAttachmentSbsysXml as WebformElementAttachmentSbsysXml; +use Drupal\webform\WebformSubmissionInterface; /** * Provides a 'webform_attachment_os2forms_sbsys_xml' element. diff --git a/os2forms.module b/os2forms.module index eb42f898..1357b459 100644 --- a/os2forms.module +++ b/os2forms.module @@ -5,10 +5,10 @@ * OS2Forms functionality module. */ -use Drupal\migrate\Plugin\MigrationInterface; +use Drupal\Core\Form\FormStateInterface; use Drupal\migrate\Plugin\MigrateSourceInterface; +use Drupal\migrate\Plugin\MigrationInterface; use Drupal\migrate\Row; -use Drupal\Core\Form\FormStateInterface; /** * Implements hook_entity_type_build(). diff --git a/src/Plugin/WebformHandler/SaveToFileWebformHandler.php b/src/Plugin/WebformHandler/SaveToFileWebformHandler.php index d2f16107..fcb783fa 100644 --- a/src/Plugin/WebformHandler/SaveToFileWebformHandler.php +++ b/src/Plugin/WebformHandler/SaveToFileWebformHandler.php @@ -5,9 +5,9 @@ use Drupal\Component\Serialization\Json; use Drupal\Core\File\Exception\FileWriteException; use Drupal\Core\File\FileSystemInterface; +use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Routing\TrustedRedirectResponse; use Drupal\Core\Serialization\Yaml; -use Drupal\Core\Form\FormStateInterface; use Drupal\file\Entity\File; use Drupal\webform\Element\WebformMessage; use Drupal\webform\Plugin\WebformElement\BooleanBase; From 582e24ca6ee60af53a39eea481c79555701a2a85 Mon Sep 17 00:00:00 2001 From: Stanislav Kutasevits Date: Tue, 4 Jul 2023 16:05:59 +0300 Subject: [PATCH 04/14] S2FRMS-37 - pdf attachment elements selecting --- CHANGELOG.md | 2 + .../src/Element/AttachmentElement.php | 50 +++++++++++++++++++ .../WebformElement/AttachmentElement.php | 31 ++++++++++++ 3 files changed, 83 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7ba1a9f1..9a27d3fd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,8 @@ before starting to add changes. Use example [placed in the end of the page](#exa ## [Unreleased] +- S2FRMS-37 - PDF attachment elements choosing + ## [3.7.0] 2023-06-22 - [S2FRMS-18] - Fixing PDF styles diff --git a/modules/os2forms_attachment/src/Element/AttachmentElement.php b/modules/os2forms_attachment/src/Element/AttachmentElement.php index 6957e9ec..05d37e4c 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\webform\Entity\WebformSubmission; use Drupal\webform\WebformSubmissionInterface; use Drupal\webform_attachment\Element\WebformAttachmentBase; @@ -27,6 +28,9 @@ public function getInfo() { * {@inheritdoc} */ public static function getFileContent(array $element, WebformSubmissionInterface $webform_submission) { + // Override webform settings. + static::overrideWebformSettings($element, $webform_submission); + /** @var \Drupal\entity_print\Plugin\EntityPrintPluginManagerInterface $print_engine_manager */ $print_engine_manager = \Drupal::service('plugin.manager.entity_print.print_engine'); @@ -87,4 +91,50 @@ public static function getFileName(array $element, WebformSubmissionInterface $w } } + /** + * Overrides connected webform settings. + * + * Does that by creating a duplicate webform element with connected to a + * webform with the settings updated. + * + * @param array $element + * The webform attachment element. + * @param \Drupal\webform\WebformSubmissionInterface $webform_submission + * A webform submission. + */ + public static function overrideWebformSettings(array $element, WebformSubmissionInterface &$webform_submission) { + $webform = $webform_submission->getWebform(); + + // Rewriting webform settings. + $webform->setSetting('submission_excluded_elements', $element['#excluded_elements'] ?? FALSE); + $webform->setSetting('submission_exclude_empty', $element['#exclude_empty'] ?? FALSE); + $webform->setSetting('submission_exclude_empty_checkbox', $element['#exclude_empty_checkbox'] ?? FALSE); + + // Creating temporary submission to be able to swap original webform + // settings. + $webform_submission_temp = WebformSubmission::create([ + 'webform' => $webform, + 'entity_type' => $webform_submission->getEntityTypeId(), + 'entity_id' => $webform_submission->id(), + 'data' => $webform_submission->getData(), + ]); + // Clone ids. + $webform_submission_temp->set('serial', $webform_submission->get('serial')->value); + $webform_submission_temp->set('token', $webform_submission->get('token')->value); + // Clone states. + $webform_submission_temp->set('in_draft', $webform_submission->get('in_draft')->value); + $webform_submission_temp->set('current_page', $webform_submission->get('current_page')->value); + // Clone timestamps. + $webform_submission_temp->set('created', $webform_submission->get('created')->value); + $webform_submission_temp->set('changed', $webform_submission->get('changed')->value); + $webform_submission_temp->set('completed', $webform_submission->get('completed')->value); + // Clone admin notes, sticky, and locked. + $webform_submission_temp->set('notes', $webform_submission->get('notes')->value); + $webform_submission_temp->set('sticky', $webform_submission->get('sticky')->value); + $webform_submission_temp->set('sticky', $webform_submission->get('locked')->value); + + // Finalize cloning: swap the webform submission. + $webform_submission = $webform_submission_temp; + } + } diff --git a/modules/os2forms_attachment/src/Plugin/WebformElement/AttachmentElement.php b/modules/os2forms_attachment/src/Plugin/WebformElement/AttachmentElement.php index 27c42e1a..dca733fb 100644 --- a/modules/os2forms_attachment/src/Plugin/WebformElement/AttachmentElement.php +++ b/modules/os2forms_attachment/src/Plugin/WebformElement/AttachmentElement.php @@ -27,6 +27,9 @@ protected function defineDefaultProperties() { 'view_mode' => 'html', 'template' => '', 'export_type' => '', + 'exclude_empty' => '', + 'exclude_empty_checkbox' => '', + 'excluded_elements' => '', ] + parent::defineDefaultProperties(); // PDF documents should never be trimmed. unset($properties['trim']); @@ -88,6 +91,34 @@ public function form(array $form, FormStateInterface $form_state) { // Set #access so that help is always visible. WebformElementHelper::setPropertyRecursive($form['attachment']['help'], '#access', TRUE); + // Elements. + $form['elements'] = [ + '#type' => 'details', + '#title' => $this->t('Included email values/markup'), + '#description' => $this->t('The selected elements will be included in the [webform_submission:values] token. Individual values may still be printed if explicitly specified as a [webform_submission:values:?] in the email body template.'), + '#open' => $this->configuration['excluded_elements'] ? TRUE : FALSE, + ]; + $form['elements']['excluded_elements'] = [ + '#type' => 'webform_excluded_elements', + '#exclude_markup' => FALSE, + '#webform_id' => $this->webform->id(), + '#default_value' => $this->configuration['excluded_elements'], + ]; + $form['elements']['exclude_empty'] = [ + '#type' => 'checkbox', + '#title' => $this->t('Exclude empty elements'), + '#description' => $this->t('If checked, empty elements will be excluded from the email values.'), + '#return_value' => TRUE, + '#default_value' => $this->configuration['exclude_empty'], + ]; + $form['elements']['exclude_empty_checkbox'] = [ + '#type' => 'checkbox', + '#title' => $this->t('Exclude unselected checkboxes'), + '#description' => $this->t('If checked, empty checkboxes will be excluded from the email values.'), + '#return_value' => TRUE, + '#default_value' => $this->configuration['exclude_empty_checkbox'], + ]; + return $form; } From 7ec7e9c0c88d3cc51bfa3e9253623b4a903073b7 Mon Sep 17 00:00:00 2001 From: Stanislav Kutasevits Date: Fri, 7 Jul 2023 11:03:51 +0300 Subject: [PATCH 05/14] OS-57 SBSIP XML element - Computed TWIG --- CHANGELOG.md | 2 + .../WebformAttachmentSbsysXml.php | 38 ++++++++----------- 2 files changed, 17 insertions(+), 23 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7ba1a9f1..73c10db0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,8 @@ before starting to add changes. Use example [placed in the end of the page](#exa ## [Unreleased] +- [OS-57] - SBSIP XML element - Computed TWIG + ## [3.7.0] 2023-06-22 - [S2FRMS-18] - Fixing PDF styles diff --git a/modules/os2forms_sbsys/src/Plugin/WebformElement/WebformAttachmentSbsysXml.php b/modules/os2forms_sbsys/src/Plugin/WebformElement/WebformAttachmentSbsysXml.php index aa7ebbce..4fde7727 100644 --- a/modules/os2forms_sbsys/src/Plugin/WebformElement/WebformAttachmentSbsysXml.php +++ b/modules/os2forms_sbsys/src/Plugin/WebformElement/WebformAttachmentSbsysXml.php @@ -5,6 +5,10 @@ use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Form\FormStateInterface; use Drupal\os2forms\Plugin\WebformElement\WebformAttachmentXml; +use Drupal\os2forms_nemid\Plugin\WebformElement\NemidElementBase; +use Drupal\webform\Plugin\WebformElement\DateBase; +use Drupal\webform\Plugin\WebformElement\TextBase; +use Drupal\webform\Plugin\WebformElement\WebformComputedBase; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -110,31 +114,19 @@ public function form(array $form, FormStateInterface $form_state) { $elements = $webform->getElementsInitializedAndFlattened(); $element_options = ['' => $this->t('None')]; foreach ($elements as $element_key => $element) { - $element_plugin = $this->elementManager->getElementInstance($element); - $allowed_elements = [ - 'textfield', - 'select', - 'email', - 'os2forms_nemid_cpr', - 'os2forms_nemid_name', - 'os2forms_nemid_pid', - 'os2forms_nemid_address', - 'os2forms_nemid_coaddress', - 'os2forms_nemid_zipcode', - 'os2forms_nemid_city', - 'os2forms_nemid_company_cvr', - 'os2forms_nemid_company_name', - 'os2forms_nemid_company_address', - 'os2forms_nemid_company_city', - 'os2forms_nemid_company_rid', - 'date', - ]; - if (!$element_plugin->isInput($element) - || !isset($element['#type']) - || !in_array($element['#type'], $allowed_elements) - || $element_plugin->hasMultipleValues($element)) { + $elementInstance = $this->elementManager->getElementInstance($element); + + // Skipping if not input or has multiple values. + if (!$elementInstance->isInput($element) + || $elementInstance->hasMultipleValues($element)) { + continue; + } + + // Skipping if is of type we do not support. + if (!$elementInstance instanceof TextBase && !$elementInstance instanceof NemidElementBase && !$elementInstance instanceof DateBase && !$elementInstance instanceof WebformComputedBase) { continue; } + $element_options[$element_key] = (isset($element['#title'])) ? new FormattableMarkup('@title (@key)', [ '@title' => $element['#title'], '@key' => $element_key, From 277a7d9ebf9afe55bbc98d43bcdaa45808d7e9d6 Mon Sep 17 00:00:00 2001 From: Stanislav Kutasevits Date: Mon, 10 Jul 2023 10:22:46 +0300 Subject: [PATCH 06/14] S2FRMS-37 - changing fieldset title --- .../src/Plugin/WebformElement/AttachmentElement.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/os2forms_attachment/src/Plugin/WebformElement/AttachmentElement.php b/modules/os2forms_attachment/src/Plugin/WebformElement/AttachmentElement.php index dca733fb..4f2215d6 100644 --- a/modules/os2forms_attachment/src/Plugin/WebformElement/AttachmentElement.php +++ b/modules/os2forms_attachment/src/Plugin/WebformElement/AttachmentElement.php @@ -94,7 +94,7 @@ public function form(array $form, FormStateInterface $form_state) { // Elements. $form['elements'] = [ '#type' => 'details', - '#title' => $this->t('Included email values/markup'), + '#title' => $this->t('Included elements'), '#description' => $this->t('The selected elements will be included in the [webform_submission:values] token. Individual values may still be printed if explicitly specified as a [webform_submission:values:?] in the email body template.'), '#open' => $this->configuration['excluded_elements'] ? TRUE : FALSE, ]; From 2e54850024d8cbca46f76efc0430b16c287a2094 Mon Sep 17 00:00:00 2001 From: Stanislav Kutasevits Date: Wed, 12 Jul 2023 11:50:55 +0300 Subject: [PATCH 07/14] Preparing 3.8.0 release --- CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a27d3fd..8bd24633 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,7 +11,9 @@ before starting to add changes. Use example [placed in the end of the page](#exa ## [Unreleased] -- S2FRMS-37 - PDF attachment elements choosing +## [3.8.0] 2023-07-12 + +- [S2FRMS-37] - PDF attachment elements choosing ## [3.7.0] 2023-06-22 From de3bb1b80401629c4ab73af1d2610b01fc5f4fa8 Mon Sep 17 00:00:00 2001 From: jekuaitk Date: Thu, 13 Jul 2023 17:04:54 +0200 Subject: [PATCH 08/14] Fix: Redirect to configured auth provider --- CHANGELOG.md | 2 ++ .../src/EventSubscriber/NemloginRedirectSubscriber.php | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8bd24633..20cb9a63 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,8 @@ before starting to add changes. Use example [placed in the end of the page](#exa ## [Unreleased] +- Fixed issue with wrong authorization provider used when multiple are enabled + ## [3.8.0] 2023-07-12 - [S2FRMS-37] - PDF attachment elements choosing diff --git a/modules/os2forms_nemid/src/EventSubscriber/NemloginRedirectSubscriber.php b/modules/os2forms_nemid/src/EventSubscriber/NemloginRedirectSubscriber.php index 107cc319..ac01bccb 100644 --- a/modules/os2forms_nemid/src/EventSubscriber/NemloginRedirectSubscriber.php +++ b/modules/os2forms_nemid/src/EventSubscriber/NemloginRedirectSubscriber.php @@ -171,7 +171,7 @@ public function redirectToNemlogin(GetResponseEvent $event) { if (!$authProviderPlugin->isAuthenticated()) { // Redirect directly to the external IdP. - $response = new RedirectResponse($this->nemloginAuthProvider->getLoginUrl()->toString()); + $response = new RedirectResponse($this->nemloginAuthProvider->getLoginUrl([], $authProviderPlugin->getPluginId())->toString()); $event->setResponse($response); $event->stopPropagation(); } From 7abae2d1b13ab4d4ed1b68df763962c22f934fd6 Mon Sep 17 00:00:00 2001 From: Stanislav Kutasevits Date: Wed, 2 Aug 2023 13:31:14 +0300 Subject: [PATCH 09/14] NemID fields populate caching issue --- CHANGELOG.md | 2 ++ .../src/EventSubscriber/NemloginRedirectSubscriber.php | 7 +++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 20cb9a63..a235a139 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,8 @@ before starting to add changes. Use example [placed in the end of the page](#exa ## [Unreleased] +- Fixed NemID fields populate caching issue + - Fixed issue with wrong authorization provider used when multiple are enabled ## [3.8.0] 2023-07-12 diff --git a/modules/os2forms_nemid/src/EventSubscriber/NemloginRedirectSubscriber.php b/modules/os2forms_nemid/src/EventSubscriber/NemloginRedirectSubscriber.php index ac01bccb..6297a076 100644 --- a/modules/os2forms_nemid/src/EventSubscriber/NemloginRedirectSubscriber.php +++ b/modules/os2forms_nemid/src/EventSubscriber/NemloginRedirectSubscriber.php @@ -147,6 +147,9 @@ public function redirectToNemlogin(GetResponseEvent $event) { return; } + // Killing cache on webform so that populated values are never cached. + $this->pageCacheKillSwitch->trigger(); + $webformNemidSettings = $webform->getThirdPartySetting('os2forms', 'os2forms_nemid'); // Getting nemlogin_auto_redirect setting. @@ -156,10 +159,6 @@ public function redirectToNemlogin(GetResponseEvent $event) { } // Checking if $nemlogin_auto_redirect is on. if ($nemlogin_auto_redirect) { - // Killing cache so that positive or negative redirect decision is not - // cached. - $this->pageCacheKillSwitch->trigger(); - // Getting auth plugin ID override. $authPluginId = NULL; if (isset($webformNemidSettings['session_type']) && !empty($webformNemidSettings['session_type'])) { From ac61fdad6f1a0b249ed07c5f0a4baaabfa5c2d05 Mon Sep 17 00:00:00 2001 From: Stanislav Kutasevits Date: Wed, 2 Aug 2023 13:32:05 +0300 Subject: [PATCH 10/14] preparing 3.8.1 --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a235a139..2a3835e6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,9 +11,10 @@ before starting to add changes. Use example [placed in the end of the page](#exa ## [Unreleased] -- Fixed NemID fields populate caching issue +## [3.8.1] 2023-08-02 - Fixed issue with wrong authorization provider used when multiple are enabled +- Fixed NemID fields populate caching issue ## [3.8.0] 2023-07-12 From 6a8596aa2b77ae68596cdc040ce321518a438696 Mon Sep 17 00:00:00 2001 From: Stanislav Kutasevits Date: Thu, 17 Aug 2023 14:18:22 +0300 Subject: [PATCH 11/14] Fixing webform fetching from NemID Nemlogin link --- .../src/Element/NemidNemloginLink.php | 41 ++++++++++++++++--- 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/modules/os2forms_nemid/src/Element/NemidNemloginLink.php b/modules/os2forms_nemid/src/Element/NemidNemloginLink.php index 8574ad47..22394e32 100644 --- a/modules/os2forms_nemid/src/Element/NemidNemloginLink.php +++ b/modules/os2forms_nemid/src/Element/NemidNemloginLink.php @@ -4,6 +4,7 @@ use Drupal\Core\Link as CoreLink; use Drupal\Core\Render\Element\Link; +use Drupal\webform\Entity\Webform; /** * Provides a render element for more. @@ -19,6 +20,8 @@ public static function preRenderLink($element) { /** @var \Drupal\os2web_nemlogin\Service\AuthProviderService $authProviderService */ $authProviderService = \Drupal::service('os2web_nemlogin.auth_provider'); + $route_name = \Drupal::routeMatch()->getRouteName(); + $nemlogin_link_login_text = NULL; if (isset($element['#nemlogin_link_login_text'])) { $nemlogin_link_login_text = $element['#nemlogin_link_login_text']; @@ -29,13 +32,40 @@ public static function preRenderLink($element) { $nemlogin_link_logout_text = $element['#nemlogin_link_logout_text']; } + /** @var \Drupal\webform\WebformInterface $webform */ + $webform = NULL; + + if ($route_name === 'entity.webform.canonical') { + $webform = \Drupal::request()->attributes->get('webform'); + } + else { + $node = \Drupal::request()->attributes->get('node'); + $nodeType = $node->getType(); + + // Search if this node type is related with field of type 'webform'. + $webformFieldMap = \Drupal::service('entity_field.manager')->getFieldMapByFieldType('webform'); + if (isset($webformFieldMap['node'])) { + foreach ($webformFieldMap['node'] as $field_name => $field_meta) { + // We found field of type 'webform' in this node, let's try fetching + // the webform. + if (in_array($nodeType, $field_meta['bundles'])) { + if ($webformId = $node->get($field_name)->target_id) { + $webform = Webform::load($webformId); + break; + } + } + } + } + } + // Getting auth plugin ID override. $authPluginId = NULL; - /** @var \Drupal\webform\Entity\Webform $webform */ - $webform = \Drupal::request()->attributes->get('webform'); - $webformNemidSettings = $webform->getThirdPartySetting('os2forms', 'os2forms_nemid'); - if (isset($webformNemidSettings['session_type']) && !empty($webformNemidSettings['session_type'])) { - $authPluginId = $webformNemidSettings['session_type']; + + if ($webform) { + $webformNemidSettings = $webform->getThirdPartySetting('os2forms', 'os2forms_nemid'); + if (isset($webformNemidSettings['session_type']) && !empty($webformNemidSettings['session_type'])) { + $authPluginId = $webformNemidSettings['session_type']; + } } // Checking if we have a share webform route, if yes open link in a new @@ -44,7 +74,6 @@ public static function preRenderLink($element) { 'entity.webform.share_page', 'entity.webform.share_page.javascript', ]; - $route_name = \Drupal::routeMatch()->getRouteName(); $options = []; if (in_array($route_name, $webformShareRoutes)) { From 0e66553e493d595097ee49630fcfbc7a334cdf42 Mon Sep 17 00:00:00 2001 From: Stanislav Kutasevits Date: Thu, 17 Aug 2023 14:23:44 +0300 Subject: [PATCH 12/14] Preparing 3.8.2 --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2a3835e6..773afbee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,10 @@ before starting to add changes. Use example [placed in the end of the page](#exa ## [Unreleased] +## [3.8.2] 2023-08-17 + +- Fixed webform fetching from NemID Nemlogin link + ## [3.8.1] 2023-08-02 - Fixed issue with wrong authorization provider used when multiple are enabled From dc017921d1055dd0323bc8b837af9edc5592aaf3 Mon Sep 17 00:00:00 2001 From: Stanislav Kutasevits Date: Thu, 17 Aug 2023 17:05:56 +0300 Subject: [PATCH 13/14] Fixing webform fetching from NemID Nemlogin link --- CHANGELOG.md | 4 ++++ modules/os2forms_nemid/src/Element/NemidNemloginLink.php | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 773afbee..77129be3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,10 @@ before starting to add changes. Use example [placed in the end of the page](#exa ## [Unreleased] +## [3.8.3] 2023-08-17 + +- Fixed webform fetching from NemID Nemlogin link + ## [3.8.2] 2023-08-17 - Fixed webform fetching from NemID Nemlogin link diff --git a/modules/os2forms_nemid/src/Element/NemidNemloginLink.php b/modules/os2forms_nemid/src/Element/NemidNemloginLink.php index 22394e32..e8f8563a 100644 --- a/modules/os2forms_nemid/src/Element/NemidNemloginLink.php +++ b/modules/os2forms_nemid/src/Element/NemidNemloginLink.php @@ -38,7 +38,7 @@ public static function preRenderLink($element) { if ($route_name === 'entity.webform.canonical') { $webform = \Drupal::request()->attributes->get('webform'); } - else { + elseif ($route_name == 'entity.node.canonical') { $node = \Drupal::request()->attributes->get('node'); $nodeType = $node->getType(); From 1da8ba51f362cdd47c98532842a65eef5b82c11b Mon Sep 17 00:00:00 2001 From: Stanislav Kutasevits Date: Tue, 22 Aug 2023 11:51:24 +0300 Subject: [PATCH 14/14] Preparing 3.9.0 --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 80111667..0674a78d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,8 @@ before starting to add changes. Use example [placed in the end of the page](#exa ## [Unreleased] +## [3.9.0] 2023-08-22 + - [OS-57] - SBSIP XML element - Computed TWIG ## [3.8.3] 2023-08-17