get('search_embedded_form.submit_count'); $form['name'] = [ '#type' => 'textfield', '#title' => $this->t('Your name'), '#maxlength' => 255, '#default_value' => '', '#required' => TRUE, '#description' => $this->t('Times form has been submitted: %count', ['%count' => $count]), ]; $form['actions'] = ['#type' => 'actions']; $form['actions']['submit'] = [ '#type' => 'submit', '#value' => $this->t('Send away'), ]; return $form; } /** * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { $state = \Drupal::state(); $submit_count = (int) $state->get('search_embedded_form.submit_count'); $state->set('search_embedded_form.submit_count', $submit_count + 1); drupal_set_message($this->t('Test form was submitted')); } }