You are here

public function TestMultipleFormController::testMultipleForms in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/modules/block/tests/modules/block_test/src/Controller/TestMultipleFormController.php \Drupal\block_test\Controller\TestMultipleFormController::testMultipleForms()
1 string reference to 'TestMultipleFormController::testMultipleForms'
block_test.routing.yml in core/modules/block/tests/modules/block_test/block_test.routing.yml
core/modules/block/tests/modules/block_test/block_test.routing.yml

File

core/modules/block/tests/modules/block_test/src/Controller/TestMultipleFormController.php, line 17
Contains \Drupal\block_test\Controller\TestMultipleFormController.

Class

TestMultipleFormController
Controller for block_test module

Namespace

Drupal\block_test\Controller

Code

public function testMultipleForms() {
  $form_state = new FormState();
  $build = [
    'form1' => $this
      ->formBuilder()
      ->buildForm('\\Drupal\\block_test\\Form\\TestForm', $form_state),
    'form2' => $this
      ->formBuilder()
      ->buildForm('\\Drupal\\block_test\\Form\\FavoriteAnimalTestForm', $form_state),
  ];

  // Output all attached placeholders trough drupal_set_message(), so we can
  // see if there's only one in the tests.
  $post_render_callable = function ($elements) {
    $matches = [];
    preg_match_all('<form\\s(.*?)action="(.*?)"(.*)>', $elements, $matches);
    $action_values = $matches[2];
    foreach ($action_values as $action_value) {
      drupal_set_message('Form action: ' . $action_value);
    }
    return $elements;
  };
  $build['#post_render'] = [
    $post_render_callable,
  ];
  return $build;
}