diff --git a/src/WebformEncryptSubmissionStorage.php b/src/WebformEncryptSubmissionStorage.php index e30b3c6..0dafb2d 100644 --- a/src/WebformEncryptSubmissionStorage.php +++ b/src/WebformEncryptSubmissionStorage.php @@ -151,8 +151,6 @@ class WebformEncryptSubmissionStorage extends WebformSubmissionStorage { $encrypted_data = $this->encryptElements($data_original, $webform); $entity->setData($encrypted_data); - $this->invokeWebformElements('preSave', $entity); - $this->invokeWebformHandlers('preSave', $entity); return $id; } diff --git a/tests/modules/webform_encrypt_test/config/install/webform.webform.test_encryption.yml b/tests/modules/webform_encrypt_test/config/install/webform.webform.test_encryption.yml index a24f62b..65cdc34 100644 --- a/tests/modules/webform_encrypt_test/config/install/webform.webform.test_encryption.yml +++ b/tests/modules/webform_encrypt_test/config/install/webform.webform.test_encryption.yml @@ -125,4 +125,12 @@ access: roles: { } users: { } permissions: { } -handlers: { } +handlers: + test_handler: + id: text_webform_handler + label: 'Test Handler' + handler_id: test_handler + status: true + conditions: { } + weight: 0 + settings: { } diff --git a/tests/modules/webform_encrypt_test/src/Plugin/WebformHandler/TestWebformHandler.php b/tests/modules/webform_encrypt_test/src/Plugin/WebformHandler/TestWebformHandler.php new file mode 100644 index 0000000..1b03b98 --- /dev/null +++ b/tests/modules/webform_encrypt_test/src/Plugin/WebformHandler/TestWebformHandler.php @@ -0,0 +1,68 @@ +state = $state; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { + return new static( + $configuration, + $plugin_id, + $plugin_definition, + $container->get('logger.factory'), + $container->get('config.factory'), + $container->get('entity_type.manager'), + $container->get('webform_submission.conditions_validator'), + $container->get('state') + ); + } + + /** + * {@inheritdoc} + */ + public function preSave(WebformSubmissionInterface $webform_submission) { + $counter = $this->state->get('test_webform_handler_counter', 0); + $this->state->set('test_webform_handler_counter', ++$counter); + } + +} diff --git a/tests/src/Kernel/WebformEncryptSubmissionStorageTest.php b/tests/src/Kernel/WebformEncryptSubmissionStorageTest.php index 1b2c1a8..38a9b12 100644 --- a/tests/src/Kernel/WebformEncryptSubmissionStorageTest.php +++ b/tests/src/Kernel/WebformEncryptSubmissionStorageTest.php @@ -122,4 +122,48 @@ class WebformEncryptSubmissionStorageTest extends KernelTestBase { } + /** + * Tests 'preSave' handlers are called only once. + */ + public function testPreSaveHandlersAreCalledOnce() { + $this->assertEquals(NULL, $this->container->get('state')->get('test_webform_handler_counter')); + + $webform = Webform::load('test_encryption'); + $values = [ + 'id' => 'webform_submission_test', + 'webform_id' => $webform->id(), + 'data' => [ + 'test_text_field' => 'Test text field value', + 'test_multiple_text_field' => [ + 0 => 'Test multiple text field value 1', + ], + 'test_text_area' => 'Test text area value', + 'test_not_encrypted' => 'Test not encrypted value', + 'test_address_field' => [ + 'address' => 'Test address field address', + 'address_2' => 'Test address field address 2', + 'city' => 'Test address field city', + 'state_province' => 'California', + 'postal_code' => 'AA11AA', + 'country' => 'United Kingdom', + ], + 'test_multiple_address_field' => [ + 0 => [ + 'address' => 'Test multiple address field address', + 'address_2' => 'Test multiple address field address 2', + 'city' => 'Test multiple address field city', + 'state_province' => 'California', + 'postal_code' => 'AA11AA', + 'country' => 'United Kingdom', + ], + ], + ], + ]; + /** @var \Drupal\webform\WebformSubmissionInterface $webform_submission */ + $webform_submission = WebformSubmission::create($values); + $webform_submission->save(); + + $this->assertEquals(1, $this->container->get('state')->get('test_webform_handler_counter')); + } + }