Hi, I have a drupal 9 (9.1.4) site with a basic page inside which I have inserted this code to open a modal window linked to another basic page like this:

<div class = "wp-block-button column__cta is-style-outline"> <a class = "wp-block-button__link use-ajax" data-dialog-type = "modal" href = "https://mydomain.com/web/mypage ">
Find out more </a> </div>

I have a problem: the modal is only opened if the user is logged in. If I access the site as an anonymous user, the modal is not displayed but I am returned to the linked page (https://mydomain.com/web/mypage). Anyone know why?
I ruled out a permissions issue on the landing page because if that were the case it would have given me an error. But I have no mistakes about it.

Thanks a lot to everyone

Claudio. 

edit: 

I saw that libraries need to be imported
  - core / jquery
   - core / drupal.dialog.ajax
but it looks like these are already in my * .libraries.yml
yet it doesn't work.

Comments

wombatbuddy’s picture

/**
 * Implements hook_page_attachments().
 */
function YOUR_MODULE_page_attachments(array &$attachments) {
  if (\Drupal::currentUser()->isAnonymous()) {
    $attachments['#attached']['library'][] = 'core/drupal.dialog.ajax';
  }
}

See 'Drupal 8: core javascript files for anonymous users'.

Claudio Fabio Mazzarago’s picture

thanks! :)