You are here

public function WebformEncryptSubmissionStorage::decryptElements in Webform Encrypt 8

Helper function to recursively decrypt fields.

Parameters

\Drupal\webform\WebformSubmissionInterface $webform_submission: The webform submission to work on.

bool $check_permissions: Flag that controls permissions check.

Return value

array Array of form data with the value now decrypted for those elements setup for being processed by an encryption profile.

Throws

\Drupal\encrypt\Exception\EncryptException

2 calls to WebformEncryptSubmissionStorage::decryptElements()
WebformEncryptSubmissionStorage::doPostSave in src/WebformEncryptSubmissionStorage.php
Performs post save entity processing.
WebformEncryptSubmissionStorage::loadData in src/WebformEncryptSubmissionStorage.php
Save webform submission data from the 'webform_submission_data' table.

File

src/WebformEncryptSubmissionStorage.php, line 195

Class

WebformEncryptSubmissionStorage
Alter webform submission storage definitions.

Namespace

Drupal\webform_encrypt

Code

public function decryptElements(WebformSubmissionInterface $webform_submission, $check_permissions = TRUE) {

  // Load webform.
  $webform = $webform_submission
    ->getWebform();

  // Load submission data.
  $data = $webform_submission
    ->getData();

  // Load the configuration.
  $config = $webform
    ->getThirdPartySetting('webform_encrypt', 'element');
  foreach ($data as $element_name => $value) {
    if (isset($config[$element_name]) && $config[$element_name]['encrypt']) {
      if (is_array($value)) {
        $this
          ->decryptChildren($data[$element_name], $check_permissions);
      }
      else {
        $decrypted_value = $this
          ->decrypt($value, $check_permissions);

        // Save the decrypted data value.
        $data[$element_name] = $decrypted_value;
      }
    }
  }
  return $data;
}