You are here

public function LockrAdvancedForm::validateForm in Lockr 8.2

Same name and namespace in other branches
  1. 8.4 src/Form/LockrAdvancedForm.php \Drupal\lockr\Form\LockrAdvancedForm::validateForm()
  2. 8.3 src/Form/LockrAdvancedForm.php \Drupal\lockr\Form\LockrAdvancedForm::validateForm()
  3. 4.x src/Form/LockrAdvancedForm.php \Drupal\lockr\Form\LockrAdvancedForm::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 FormInterface::validateForm

File

src/Form/LockrAdvancedForm.php, line 89

Class

LockrAdvancedForm

Namespace

Drupal\lockr\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
  if (!$form_state
    ->getValue('custom')) {
    return;
  }
  $cert_path = $form_state
    ->getValue('custom_cert');
  if (!$cert_path) {
    $form_state
      ->setErrorByName('custom_cert', $this
      ->t('Certificate location is required for custom certs'));
    return;
  }
  if (substr($cert_path, 0, 10) === 'private://') {
    $private_stream = new PrivateStream();
    $private_stream
      ->setUri($cert_path);
    $cert_path = $private_stream
      ->realpath();
  }
  elseif ($cert_path[0] !== '/') {
    $cert_path = "{$this->drupalRoot}/{$cert_path}";
  }
  if (is_dir($cert_path) || !is_readable($cert_path)) {
    $form_state
      ->setErrorByName('custom_cert', 'Certificate must be a readable file');
  }
}