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) diff --git a/modules/os2forms_encrypt/src/Commands/Os2FormsEncryptCommands.php b/modules/os2forms_encrypt/src/Commands/Os2FormsEncryptCommands.php index a34153e..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'); @@ -66,12 +71,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;