Please Disable Your Browser Adblock Extension for our site and Refresh This Page!

our ads are user friendly, we do not serve popup ads. We serve responsible ads!

Refresh Page
Skip to main content
On . By CodimTh

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.

Riadh Rahmi

Senior Web Developer PHP/Drupal & Laravel

I am a senior web developer, I have experience in planning and developing large scale dynamic web solutions especially in Drupal & Laravel.

Web Posts


Page Facebook