Hi i am using Drupal 8 to render a modal popup on clicking a link. However when i am connected as admin the popup render well but as soon as i logout or choose to be incognito mode of the browser the popup does not appear and the page is redirected to link set in the href tag. Here is my link :

<a href="/mysite.com/contact/download_file_advance?nid=371" class="use-ajax" data-dialog-type="modal" data-accepts="application/vnd.drupal-modal" data-filename="Livre Blanc">SOME TEXT IN MODAL</a>

Can anyone explain to me why this is so? I can't figure out why when i am connected the modal render well but when not connected it redirect me to the node.

  • have you checked your permissions. – vijay Mar 27 '17 at 7:38
  • @vijay Where can i chek the permission? – EXE Mar 27 '17 at 7:44
  • check it in admin/modules there will be options like configuration, permissions, etc., for each module – vijay Mar 27 '17 at 7:50
  • @vijay I am not using any module to display the modal...Infact am using the core module modal provided by drupal 8 itself. I have created a user having role as Authenticated User only but when login using this user also the modal does not appear. – EXE Mar 27 '17 at 7:55
  • I think anonymous user is missing the modal library. Either use proper render arrays or add the library via hook_page_attachments – user21641 Mar 27 '17 at 8:34

Ajay is correct, the javascript dependencies wont load by default for anonymous users. Here's what I added to my theme.libraries.yml to get it working:

dependencies: 
  - core/jquery
  - core/drupal.dialog.ajax

You need to add code dependencies in your theme for ajax and jQuery in your theme.libraries.yml file.

Drupal by default does not load ajax for anonymous users.

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.