246bcea58f88d6e9b974a81690714ae11a29d4b6
[yaffs-website] / web / core / modules / block / tests / modules / block_test / src / Controller / TestMultipleFormController.php
1 <?php
2
3 namespace Drupal\block_test\Controller;
4
5 use Drupal\Core\Controller\ControllerBase;
6 use Drupal\Core\Form\FormState;
7
8 /**
9  * Controller for block_test module
10  */
11 class TestMultipleFormController extends ControllerBase {
12
13   public function testMultipleForms() {
14     $form_state = new FormState();
15     $build = [
16       'form1' => $this->formBuilder()->buildForm('\Drupal\block_test\Form\TestForm', $form_state),
17       'form2' => $this->formBuilder()->buildForm('\Drupal\block_test\Form\FavoriteAnimalTestForm', $form_state),
18     ];
19
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) {
24       $matches = [];
25       preg_match_all('<form\s(.*?)action="(.*?)"(.*)>', $elements, $matches);
26
27       $action_values = $matches[2];
28
29       foreach ($action_values as $action_value) {
30         $this->messenger()->addStatus('Form action: ' . $action_value);
31       }
32       return $elements;
33     };
34
35     $build['#post_render'] = [$post_render_callable];
36
37     return $build;
38   }
39
40 }