You are here

public function WebformEncryptSubmissionStorage::encryptElements in Webform Encrypt 8

Helper function to recursively encrypt fields.

Parameters

array $data: The current form data array.

\Drupal\webform\WebformInterface $webform: The webform we are encrypting.

Return value

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

Throws

\Drupal\encrypt\Exception\EncryptException

1 call to WebformEncryptSubmissionStorage::encryptElements()
WebformEncryptSubmissionStorage::doPreSave in src/WebformEncryptSubmissionStorage.php
Performs presave entity processing.

File

src/WebformEncryptSubmissionStorage.php, line 89

Class

WebformEncryptSubmissionStorage
Alter webform submission storage definitions.

Namespace

Drupal\webform_encrypt

Code

public function encryptElements(array $data, WebformInterface $webform) {

  // Load the configuration.
  $config = $webform
    ->getThirdPartySetting('webform_encrypt', 'element');
  foreach ($data as $element_name => $value) {
    $encryption_profile = isset($config[$element_name]) ? EncryptionProfile::load($config[$element_name]['encrypt_profile']) : FALSE;

    // If the value is an array and we have a encryption profile.
    if ($encryption_profile) {
      if (is_array($value)) {
        $this
          ->encryptChildren($data[$element_name], $encryption_profile);
      }
      else {
        $encrypted_value = $this
          ->encrypt($value, $encryption_profile);

        // Save the encrypted data value.
        $data[$element_name] = $encrypted_value;
      }
    }
  }
  return $data;
}