Skip to content

Instantly share code, notes, and snippets.

@cluppi
Created December 18, 2014 13:12
Show Gist options
  • Save cluppi/4766579905a2616dda97 to your computer and use it in GitHub Desktop.
Save cluppi/4766579905a2616dda97 to your computer and use it in GitHub Desktop.
Webform Encrypt patch to support webform 4.x on top of patches applied
diff --git a/webform_encrypt.module b/webform_encrypt.module
index c74b862..16f8a8e 100644
--- a/webform_encrypt.module
+++ b/webform_encrypt.module
@@ -90,8 +90,16 @@ function webform_encrypt_webform_component_presave(&$component) {
function webform_encrypt_webform_submission_presave($node, &$submission) {
foreach ($submission->data as $cid => $entry) {
if (!empty($node->webform['components'][$cid]['extra']['encrypt'])) {
- foreach ($submission->data[$cid]['value'] as $delta => $value) {
- $submission->data[$cid]['value'][$delta] = encrypt($entry['value'][$delta], array('base64' => TRUE));
+ // Data structure has been changed in Webform 4.x, here we try to support
+ // both. See issue #1788042 for reference.
+ if (isset($submission->data[$cid]['value'])) {
+ $component = &$submission->data[$cid]['value'];
+ } else {
+ $component = &$submission->data[$cid];
+ }
+
+ foreach ($component as $delta => $value) {
+ $component[$delta] = encrypt($component[$delta], array('base64' => TRUE));
}
}
}
@@ -106,9 +114,24 @@ function webform_encrypt_webform_submission_load($submissions) {
$node = node_load($submission->nid);
foreach ($submission->data as $cid => $entry) {
if (!empty($node->webform['components'][$cid]['extra']['encrypt'])) {
- foreach ($submission->data[$cid]['value'] as $delta => $value) {
- if (!empty($entry['value'][$delta]) && @unserialize($entry['value'][$delta]) !== FALSE) {
- $submission->data[$cid]['value'][$delta] = user_access('view encrypted values') ? decrypt($entry['value'][$delta], array('base64' => TRUE)) : t('[Value Encrypted]');
+ // Data structure has been changed in Webform 4.x, here we try to support
+ // both. See issue #1788042 for reference.
+ if (isset($submission->data[$cid]['value'])) {
+ $component = &$submission->data[$cid]['value'];
+ } else {
+ $component = &$submission->data[$cid];
+ }
+
+ foreach ($component as $delta => $value) {
+ // Also try to support both webform 4.x and previous data structures.
+ if (isset($entry['value'])) {
+ $nested_component = $entry['value'];
+ } else {
+ $nested_component = $entry;
+ }
+
+ if (!empty($nested_component[$delta]) && @unserialize($nested_component[$delta]) !== FALSE) {
+ $component[$delta] = user_access('view encrypted values') ? decrypt($nested_component[$delta], array('base64' => TRUE)) : t('[Value Encrypted]');
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment