0

I'm building some modal pages using the use-ajax class plus the data-dialog-type="modal" attribute on link tags. It worked great as an admin user, but logging in as a different role(call it parent) and the links go directly to the pages.

It's pretty obvious from the sources panel in web inspector that the parent role isn't being served the necessary javascript (dialog.jquery-ui.js, dialog.js, dialog.position.js, etc).

There's nothing in the permissions that looks like it would limit the javascript added to the page.

I've tried this in my custom theme and in bartik, same result.

1

The answer is simple enough, though a little counter-intuitive coming from a Drupal 7 install where everything but the kitchen sink is included.

All I had to do was to inlcude the library in my theme's .libraries.yml file;

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

This will be more performent than including the entire core javascript system on every page. It was a little confusing since that is the behavior for the admin user.

  • 1
    you can also include the library in the build array of the modal link, then you load the library only if necessary, that is when the link is rendered: $build['#attached']['library'][] = 'core/drupal.dialog.ajax';, – 4k4 Mar 15 '18 at 21:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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