DemoBase.php in Examples for Developers 3.x
File
modules/form_api_example/src/Form/DemoBase.php
View source
<?php
namespace Drupal\form_api_example\Form;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
abstract class DemoBase extends FormBase {
public function submitForm(array &$form, FormStateInterface $form_state) {
$values = $form_state
->getValues();
foreach ($values as $key => $value) {
$label = isset($form[$key]['#title']) ? $form[$key]['#title'] : $key;
if (is_array($value)) {
$value = array_filter($value);
}
if ($value) {
$display_value = is_array($value) ? print_r($value, 1) : $value;
$message = $this
->t('Value for %title: %value', [
'%title' => $label,
'%value' => $display_value,
]);
$this
->messenger()
->addMessage($message);
}
}
}
}
Classes
Name |
Description |
DemoBase |
Implements common submit handler used in form_api_example demo forms. |