I have a controller that returns a normal renderable page array. I'd like to embed a form in that page, but the form is not appearing in the rendered output. The form is properly added to the renderable array correctly, but it's not in the final HTML for some reason. What's going on here?
Here's my controller (which extends ControllerBase through BlockController):
use Drupal\block\Controller\BlockController;
use Drupal\Core\Extension\ThemeHandlerInterface;
use Drupal\Core\Form\FormBuilderInterface;
use Drupal\Core\Render\Element;
use Symfony\Component\DependencyInjection\ContainerInterface;
class LayoutController extends BlockController {
/**
* @var \Drupal\Core\Form\FormBuilderInterface
*/
protected $formBuilder;
/**
* {@inheritdoc}
*/
public function __construct(ThemeHandlerInterface $theme_handler, FormBuilderInterface $form_builder) {
parent::__construct($theme_handler);
$this->formBuilder = $form_builder;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('theme_handler'),
$container->get('form_builder')
);
}
/**
* Overrides the region demo page, adding placeholder elements for sortable
* lists of blocks, plus a control panel form.
*
* @param string $theme
* The theme key.
*
* @return array
* The renderable page.
*/
public function layout($theme) {
$page = parent::demo($theme);
foreach (Element::children($page) as $region) {
if (isset($page[$region]['block_description'])) {
$page[$region]['block_description']['#template'] .= '<ul data-region="{{ region }}"></ul>';
$page[$region]['block_description']['#context']['region'] = $region;
}
}
$page['layout_control'] = $this->formBuilder->getForm('Drupal\block_ui\Form\LayoutControlForm');
$page['#attached']['library'][] = 'block_ui/backbone.collectionView';
return $page;
}
}