From 39b6f042a28fe4c0e819e44acf5aa686e501d8dd Mon Sep 17 00:00:00 2001 From: jekuaitk Date: Fri, 9 Aug 2024 10:16:41 +0200 Subject: [PATCH 1/3] Encrypt subelements --- .../os2forms_encrypt/src/Commands/Os2FormsEncryptCommands.php | 4 ++-- modules/os2forms_encrypt/src/Helper/Os2FormsEncryptor.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/os2forms_encrypt/src/Commands/Os2FormsEncryptCommands.php b/modules/os2forms_encrypt/src/Commands/Os2FormsEncryptCommands.php index a34153e..30deb68 100644 --- a/modules/os2forms_encrypt/src/Commands/Os2FormsEncryptCommands.php +++ b/modules/os2forms_encrypt/src/Commands/Os2FormsEncryptCommands.php @@ -66,12 +66,12 @@ public function enabledEncrypt(): void { /** @var \Drupal\webform\Entity\Webform $webform */ foreach ($webforms as $webform) { - $elements = $webform->getElementsDecoded(); + $elements = $webform->getElementsDecodedAndFlattened(); $config = $webform->getThirdPartySettings('webform_encrypt'); $changed = FALSE; foreach ($elements as $key => $element) { - if (!isset($config['element'][$key])) { + if (!isset($config['element'][$key]) || $config['element'][$key]['encrypt_profile'] === NULL) { $config['element'][$key] = [ 'encrypt' => TRUE, 'encrypt_profile' => $defaultEncryptionProfile, diff --git a/modules/os2forms_encrypt/src/Helper/Os2FormsEncryptor.php b/modules/os2forms_encrypt/src/Helper/Os2FormsEncryptor.php index bc40911..6e856ac 100644 --- a/modules/os2forms_encrypt/src/Helper/Os2FormsEncryptor.php +++ b/modules/os2forms_encrypt/src/Helper/Os2FormsEncryptor.php @@ -89,7 +89,7 @@ public function enableEncryption(WebformInterface $webform): void { } // Check that there are any elements to enable encryption on. - $elements = $webform->getElementsDecoded(); + $elements = $webform->getElementsDecodedAndFlattened(); if (empty($elements)) { return; From 9c7a3dbcad0109fe74510aa262de734a0f313380 Mon Sep 17 00:00:00 2001 From: jekuaitk Date: Fri, 9 Aug 2024 10:21:05 +0200 Subject: [PATCH 2/3] Updated CHANGELOG --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6763596..01b4c64 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] +- [#123](https://github.com/OS2Forms/os2forms/pull/123) + Encrypt subelements + ## [3.15.6] 2024-07-16 - [#120](https://github.com/OS2Forms/os2forms/pull/120) From 1bf1b0653d30964c55d91ce10c727ab783d68d9f Mon Sep 17 00:00:00 2001 From: jekuaitk Date: Fri, 9 Aug 2024 10:53:30 +0200 Subject: [PATCH 3/3] Add check for default encryption profile --- .../src/Commands/Os2FormsEncryptCommands.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/modules/os2forms_encrypt/src/Commands/Os2FormsEncryptCommands.php b/modules/os2forms_encrypt/src/Commands/Os2FormsEncryptCommands.php index 30deb68..0d5cdce 100644 --- a/modules/os2forms_encrypt/src/Commands/Os2FormsEncryptCommands.php +++ b/modules/os2forms_encrypt/src/Commands/Os2FormsEncryptCommands.php @@ -58,6 +58,11 @@ public function enabledEncrypt(): void { $defaultEncryptionProfile = $config->get('default_encryption_profile'); + if (!$defaultEncryptionProfile) { + $this->output()->writeln('Default encryption profile is missing. Set one and try again.'); + return; + } + // Get the storage for Webform entity type. $webformStorage = $this->entityTypeManager->getStorage('webform');