public function EncryptionProfileForm::validateForm in Encrypt 8.3
Form validation handler.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Overrides FormBase::validateForm
File
- src/
Form/ EncryptionProfileForm.php, line 294
Class
- EncryptionProfileForm
- Provides the form to add / edit an EncryptionProfile entity.
Namespace
Drupal\encrypt\FormCode
public function validateForm(array &$form, FormStateInterface $form_state) {
parent::validateForm($form, $form_state);
// Only validate when submitting the form, not on AJAX rebuild.
if (!$form_state
->isSubmitted()) {
return;
}
// If the profile is being edited and editing has not been confirmed yet.
if ($this->operation == "edit" && !$this->editConfirmed) {
return;
}
// If the encryption method contains a config form, validate it as well.
if ($plugin = $this->entity
->getEncryptionMethod()) {
if ($plugin instanceof EncryptionMethodPluginFormInterface) {
$plugin_form_state = $this
->createPluginFormState($form_state);
$plugin
->validateConfigurationForm($form, $plugin_form_state);
$form_state
->setValue('encryption_method_configuration', $plugin_form_state
->getValues());
$this
->moveFormStateErrors($plugin_form_state, $form_state);
$this
->moveFormStateStorage($plugin_form_state, $form_state);
}
}
$form_state
->cleanValues();
/** @var \Drupal\encrypt\Entity\EncryptionConfiguration $entity */
$this->entity = $this
->buildEntity($form, $form_state);
// Validate the EncryptionProfile entity.
$errors = $this->entity
->validate();
if ($errors) {
$form_state
->setErrorByName('encryption_key', implode(';', $errors));
}
}