You are here

public function SimplesamlphpCustomAttributesEditForm::validateForm in SimpleSAMLphp Custom Attribute Mapping 8

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/SimplesamlphpCustomAttributesEditForm.php, line 112

Class

SimplesamlphpCustomAttributesEditForm

Namespace

Drupal\simplesamlphp_custom_attributes\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
  $mappings = $this->mappingConfig
    ->get('mappings');

  // If this is a new mapping, check to make sure the same one isn't already
  // defined.
  if ($mappings && !$form_state
    ->getValue('mapping_id')) {
    foreach ($mappings as $mapping) {
      if ($mapping['attribute_name'] === $form_state
        ->getValue('attribute_name') && $mapping['field_name'] === $form_state
        ->getValue('field_name')) {
        $form_state
          ->setErrorByName('field_name', $this
          ->t('This SAML attribute has already been mapped to this field.'));
      }
    }
  }
}