You are here

public function LockrAdvancedForm::validateForm in Lockr 8.3

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

Class

LockrAdvancedForm
Form handler for advanced Lockr settings.

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;
  }
  $real_cert_path = $this->fileSystem
    ->realpath($cert_path);
  if (is_dir($real_cert_path) || !is_readable($real_cert_path)) {
    $form_state
      ->setErrorByName('custom_cert', $this
      ->t('Certificate must be a readable file'));
  }
}