public static function WebformElementEncrypt::validateWebformElementEncrypt in Webform Encrypt 8
Validates element attributes.
File
- src/
Element/ WebformElementEncrypt.php, line 90
Class
- WebformElementEncrypt
- Provides a webform element for element attributes.
Namespace
Drupal\webform_encrypt\ElementCode
public static function validateWebformElementEncrypt(&$element, FormStateInterface $form_state, &$complete_form) {
$webform = $form_state
->getFormObject()
->getWebform();
$values = $form_state
->getValues();
$element_name = $values['key'];
$config = $webform
->getThirdPartySetting('webform_encrypt', 'element');
// To avoid generating an unnecessary dependencies on webform_encrypt:
// 1. Only set our third party settings if we are encrypting the element.
// 2. Unset our third party settings if not encrypting the element.
if (isset($values['encrypt']) && $values['encrypt'] == 1) {
$config[$element_name] = [
'encrypt' => $values['encrypt'],
'encrypt_profile' => $values['encrypt_profile'],
];
}
else {
unset($config[$element_name]);
}
if (empty($config)) {
$webform
->unsetThirdPartySetting('webform_encrypt', 'element');
}
else {
$webform
->setThirdPartySetting('webform_encrypt', 'element', $config);
}
}