You are here

public function RemovalSettingsForm::validateForm in General Data Protection Regulation 8

Same name and namespace in other branches
  1. 8.2 modules/gdpr_tasks/src/Form/RemovalSettingsForm.php \Drupal\gdpr_tasks\Form\RemovalSettingsForm::validateForm()
  2. 3.0.x modules/gdpr_tasks/src/Form/RemovalSettingsForm.php \Drupal\gdpr_tasks\Form\RemovalSettingsForm::validateForm()

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

modules/gdpr_tasks/src/Form/RemovalSettingsForm.php, line 50

Class

RemovalSettingsForm
Settings form for GDPR Removal task.

Namespace

Drupal\gdpr_tasks\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
  parent::validateForm($form, $form_state);
  if ($form_state
    ->hasValue('directory')) {
    $directory = $form_state
      ->getValue('directory');
    if (empty($directory)) {
      $form_state
        ->setErrorByName('directory', $this
        ->t('The directory is required.'));
      return;
    }
    if (!\file_prepare_directory($directory)) {
      $form_state
        ->setErrorByName('directory', $this
        ->t("The directory does not exist or it's not writable."));
      return;
    }
  }
}