formBuilder = $formBuilder; } /** * {@inheritdoc} * * @param \Symfony\Component\DependencyInjection\ContainerInterface $container * The Drupal service container. * * @return static */ public static function create(ContainerInterface $container) { return new static( $container->get('form_builder') ); } /** * Callback for opening the modal form. */ public function openModalForm() { $response = new AjaxResponse(); // Get the modal form using the form builder. $modal_form = $this->formBuilder->getForm('Drupal\modal_form_example\Form\ModalForm'); // Add an AJAX command to open a modal dialog with the form as the content. $response->addCommand(new OpenModalDialogCommand('My Modal Form', $modal_form, ['width' => '800'])); return $response; } }