class TestMultipleFormController
Same name and namespace in other branches
- 11.x core/modules/block/tests/modules/block_test/src/Controller/TestMultipleFormController.php \Drupal\block_test\Controller\TestMultipleFormController
Controller for block_test module.
Hierarchy
- class \Drupal\Core\Controller\ControllerBase extends \Drupal\Core\DependencyInjection\ContainerInjectionInterface uses \Drupal\Core\Logger\LoggerChannelTrait, \Drupal\Core\Messenger\MessengerTrait, \Drupal\Core\Routing\RedirectDestinationTrait, \Drupal\Core\StringTranslation\StringTranslationTrait
- class \Drupal\block_test\Controller\TestMultipleFormController implements \Drupal\Core\Controller\ControllerBase
Expanded class hierarchy of TestMultipleFormController
File
-
core/
modules/ block/ tests/ modules/ block_test/ src/ Controller/ TestMultipleFormController.php, line 11
Namespace
Drupal\block_test\ControllerView source
class TestMultipleFormController extends ControllerBase {
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\Core\Messenger\MessengerInterface::addMessage(), 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) {
$this->messenger()
->addStatus('Form action: ' . $action_value);
}
return $elements;
};
$build['#post_render'] = [
$post_render_callable,
];
return $build;
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.