You are here

public function PrepopulateTestForm::submitForm in Prepopulate 8.2

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

tests/modules/prepopulate_test/src/Form/PrepopulateTestForm.php, line 133

Class

PrepopulateTestForm
Class PrepopulateTestForm.

Namespace

Drupal\prepopulate_test\Form

Code

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

  // Display result.
  foreach ($form_state
    ->getValues() as $key => $value) {
    if ($value instanceof MarkupInterface) {
      $value = (string) $value;
    }
    elseif ($value instanceof DrupalDateTime) {
      $value = (string) $value;
    }
    elseif (isset($value['entity']) && $value['entity'] instanceof EntityInterface) {
      $entity = $value['entity'];
      $entity
        ->save();
      $value = "{$entity->label()} ({$entity->id()})";
    }
    else {
      $value = var_export($value, TRUE);
    }
    $this
      ->messenger()
      ->addStatus($key . ': ' . $value);
  }
}