3 namespace Drupal\{{ machine_name }}\Form;
5 use Drupal\Core\Form\FormBase;
6 use Drupal\Core\Form\FormStateInterface;
9 * Provides a {{ name }} form.
11 class {{ class }} extends FormBase {
16 public function getFormId() {
17 return '{{ form_id }}';
23 public function buildForm(array $form, FormStateInterface $form_state) {
26 '#type' => 'textarea',
27 '#title' => $this->t('Message'),
34 $form['actions']['submit'] = [
36 '#value' => $this->t('Send'),
45 public function validateForm(array &$form, FormStateInterface $form_state) {
46 if (mb_strlen($form_state->getValue('message')) < 10) {
47 $form_state->setErrorByName('name', $this->t('Message should be at least 10 characters.'));
54 public function submitForm(array &$form, FormStateInterface $form_state) {
55 $this->messenger()->addStatus($this->t('The message has been sent.'));
56 $form_state->setRedirect('<front>');