function SimpleFormBlock::build
Same name in other branches
- 3.x modules/form_api_example/src/Plugin/Block/SimpleFormBlock.php \Drupal\form_api_example\Plugin\Block\SimpleFormBlock::build()
Overrides BlockPluginInterface::build
File
-
modules/
form_api_example/ src/ Plugin/ Block/ SimpleFormBlock.php, line 55
Class
- SimpleFormBlock
- Provides a 'Example: Display a form' block.
Namespace
Drupal\form_api_example\Plugin\BlockCode
public function build() {
$output = [
'description' => [
'#markup' => $this->t('Using form provided by @classname', [
'@classname' => SimpleForm::class,
]),
],
];
// Use the form builder service to retrieve a form by providing the full
// name of the class that implements the form you want to display. getForm()
// will return a render array representing the form that can be used
// anywhere render arrays are used.
//
// In this case the build() method of a block plugin is expected to return
// a render array so we add the form to the existing output and return it.
$output['form'] = $this->formBuilder
->getForm(SimpleForm::class);
return $output;
}