You are here

public function SamlSpConfig::validateForm in SAML Service Provider 8.2

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

src/Form/SamlSpConfig.php, line 68
Contains \Drupal\saml_sp\Form\SamlSpConfigSPForm.

Class

SamlSpConfig

Namespace

Drupal\saml_sp\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {

  // ensure the cert and key files are provided and exist in the system if
  // signed or encryption options require them
  $values = $form_state
    ->getValues();
  if ($values['security']['authnRequestsSigned'] || $values['security']['logoutRequestSigned'] || $values['security']['logoutResponseSigned'] || $values['security']['wantNameIdEncrypted'] || $values['security']['signMetaData']) {
    foreach ([
      'key_location',
      'cert_location',
    ] as $key) {
      if (empty($values[$key])) {
        $form_state
          ->setError($form[$key], $this
          ->t('The %field must be provided.', array(
          '%field' => $form[$key]['#title'],
        )));
      }
      else {
        if (!file_exists($values[$key])) {
          $form_state
            ->setError($form[$key], $this
            ->t('The %input file does not exist.', array(
            '%input' => $values[$key],
          )));
        }
      }
    }
  }
}