You are here

public function Captcha::preSave in YAML Form 8

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

Parameters

array $element: An element.

\Drupal\yamlform\YamlFormSubmissionInterface $yamlform_submission: A form submission.

Overrides YamlFormElementBase::preSave

File

src/Plugin/YamlFormElement/Captcha.php, line 73

Class

Captcha
Provides a 'captcha' element.

Namespace

Drupal\yamlform\Plugin\YamlFormElement

Code

public function preSave(array &$element, YamlFormSubmissionInterface $yamlform_submission) {

  // Remove all captcha related keys from the form submission's data.
  $key = $element['#yamlform_key'];
  $data = $yamlform_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]);
  }
  $yamlform_submission
    ->setData($data);
}