How to open modal in Drupal 8 without a link?

The modal does not start on the link on the page that the user clicked. The modal starts when the user reaches the URL.

Think of something like a disclaimer that appears as soon as the user arrives at the URL.

+4
source share
1 answer

You can use the function for this Drupal.dialog.

For example:

var $myDialog = $('<div>My dialog text</div>').appendTo('body');
Drupal.dialog($myDialog, {
  title: 'A title',
  buttons: [{
    text: 'Close',
    click: function() {
      $(this).dialog('close');
    }
  }]
}).showModal();

See node.preview.jsfor another example.

Refresh . To use this with an AJAX request / response:

Drupal.ajax({
  url: 'some/path',
  success: function(response) {
    var $myDialog = $('<div>' + response.data + '</div>').appendTo('body');
    Drupal.dialog($myDialog, {title: 'Some title'}).showModal();
  }
}).execute();
+6
source

Source: https://habr.com/ru/post/1618145/


All Articles