You are here

public function Captcha::preSave in Webform 8.5

Same name and namespace in other branches
  1. 6.x src/Plugin/WebformElement/Captcha.php \Drupal\webform\Plugin\WebformElement\Captcha::preSave()

Acts on a webform submission element before the presave hook is invoked.

Parameters

array $element: An element.

\Drupal\webform\WebformSubmissionInterface $webform_submission: A webform submission.

Overrides WebformElementBase::preSave

File

src/Plugin/WebformElement/Captcha.php, line 121

Class

Captcha
Provides a 'captcha' element.

Namespace

Drupal\webform\Plugin\WebformElement

Code

public function preSave(array &$element, WebformSubmissionInterface $webform_submission) {

  // Remove all captcha related keys from the webform submission's data.
  $key = $element['#webform_key'];
  $data = $webform_submission
    ->getData();
  unset($data[$key]);

  // @see \Drupal\captcha\Element\Captcha
  $sub_keys = [
    'sid',
    'token',
    'response',
  ];
  foreach ($sub_keys as $sub_key) {
    unset($data[$key . '_' . $sub_key]);
  }
  $webform_submission
    ->setData($data);
}