To render a form in a block, I can use the following code.
class LoremIpsumBlock extends BlockBase {
public function build() {
// Return the form @ Form/LoremIpsumBlockForm.php.
return \Drupal::formBuilder()->getForm('Drupal\loremipsum\Form\LoremIpsumBlockForm');
}
How can I render in a block the output of a controller? Is it possible, or do I have to duplicate the controller class code in the block class?
The example in the documentation is too simple and it shows how to render a literal string.
class HelloBlock extends BlockBase {
public function build() {
return array(
'#markup' => $this->t('Hello, World!'),
);
}
}