How to show form in popup in Drupal 8 & 9
Example how to show a custom form in popup when user click a link from front end.
If you want to make a link modal, so that it will open in a popup, you have to set the class use-ajax
and the attribute data-dialog-type
like in this example:
$content['add_movie'] = array(
'#type' => 'link',
'#title' => $this->t('Add movie'),
'#url' => Url::fromRoute('node.add', ['node_type' => 'content_type_movie']),
'#attributes' => [
'class' => ['use-ajax'],
'data-dialog-type' => 'modal',
'data-dialog-options' => Json::encode([
'width' => 700,
]),
],
);
I Hope this tips helps you.