Skip to content

Commit 7eb9447

Browse files
authored
Merge pull request #123 from OS2Forms/feature/encrypt-subelements
Encrypt subelements
2 parents e1eb43c + 1bf1b06 commit 7eb9447

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ before starting to add changes. Use example [placed in the end of the page](#exa
1111

1212
## [Unreleased]
1313

14+
- [#123](https://github.com/OS2Forms/os2forms/pull/123)
15+
Encrypt subelements
16+
1417
## [3.15.6] 2024-07-16
1518

1619
- [#120](https://github.com/OS2Forms/os2forms/pull/120)

modules/os2forms_encrypt/src/Commands/Os2FormsEncryptCommands.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ public function enabledEncrypt(): void {
5858

5959
$defaultEncryptionProfile = $config->get('default_encryption_profile');
6060

61+
if (!$defaultEncryptionProfile) {
62+
$this->output()->writeln('Default encryption profile is missing. Set one and try again.');
63+
return;
64+
}
65+
6166
// Get the storage for Webform entity type.
6267
$webformStorage = $this->entityTypeManager->getStorage('webform');
6368

@@ -66,12 +71,12 @@ public function enabledEncrypt(): void {
6671

6772
/** @var \Drupal\webform\Entity\Webform $webform */
6873
foreach ($webforms as $webform) {
69-
$elements = $webform->getElementsDecoded();
74+
$elements = $webform->getElementsDecodedAndFlattened();
7075
$config = $webform->getThirdPartySettings('webform_encrypt');
7176

7277
$changed = FALSE;
7378
foreach ($elements as $key => $element) {
74-
if (!isset($config['element'][$key])) {
79+
if (!isset($config['element'][$key]) || $config['element'][$key]['encrypt_profile'] === NULL) {
7580
$config['element'][$key] = [
7681
'encrypt' => TRUE,
7782
'encrypt_profile' => $defaultEncryptionProfile,

modules/os2forms_encrypt/src/Helper/Os2FormsEncryptor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public function enableEncryption(WebformInterface $webform): void {
8989
}
9090

9191
// Check that there are any elements to enable encryption on.
92-
$elements = $webform->getElementsDecoded();
92+
$elements = $webform->getElementsDecodedAndFlattened();
9393

9494
if (empty($elements)) {
9595
return;

0 commit comments

Comments
 (0)