3 namespace Drupal\block_test\Controller;
5 use Drupal\Core\Controller\ControllerBase;
6 use Drupal\Core\Form\FormState;
9 * Controller for block_test module
11 class TestMultipleFormController extends ControllerBase {
13 public function testMultipleForms() {
14 $form_state = new FormState();
16 'form1' => $this->formBuilder()->buildForm('\Drupal\block_test\Form\TestForm', $form_state),
17 'form2' => $this->formBuilder()->buildForm('\Drupal\block_test\Form\FavoriteAnimalTestForm', $form_state),
20 // Output all attached placeholders trough
21 // \Drupal\Core\Messenger\MessengerInterface::addMessage(), so we can
22 // see if there's only one in the tests.
23 $post_render_callable = function ($elements) {
25 preg_match_all('<form\s(.*?)action="(.*?)"(.*)>', $elements, $matches);
27 $action_values = $matches[2];
29 foreach ($action_values as $action_value) {
30 $this->messenger()->addStatus('Form action: ' . $action_value);
35 $build['#post_render'] = [$post_render_callable];