You are here

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

Form submission 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::submitForm

File

src/Form/SimplesamlphpCustomAttributesEditForm.php, line 129

Class

SimplesamlphpCustomAttributesEditForm

Namespace

Drupal\simplesamlphp_custom_attributes\Form

Code

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

  // Set up the new mapping to add to the array.
  $mapping = [
    'attribute_name' => $form_state
      ->getValue('attribute_name'),
    'field_name' => $form_state
      ->getValue('field_name'),
  ];

  // If we're editing, update the value, if we're adding, add it.
  $mapping_id = $form_state
    ->getValue('mapping_id');
  if (is_numeric($mapping_id)) {
    $mappings[$mapping_id] = $mapping;
  }
  else {
    $mappings[] = $mapping;
  }

  // Save the config with the new mappings.
  $this->mappingConfig
    ->set('mappings', $mappings)
    ->save();

  // Go back to the listing page.
  $form_state
    ->setRedirect('simplesamlphp_custom_attributes.list');
}