Problem/Motivation
Uncaught TypeError: a is undefined
when using custom initialization (drowl paragraphs):
{{ attach_library('photoswipe/photoswipe.init') }}
{{ image_rendered }}
Steps to reproduce
Proposed resolution
Remaining tasks
User interface changes
API changes
Data model changes
Issue fork photoswipe-3345311
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
anybodyThe reason is, that if attaching the library via
photoswipe/photoswipe.initthe photoswipe container (from templates/photoswipe-container.html.twig) is missing on the page.That's a problem I have no solution for yet ...
The container is added in
The question is, if this is worth solving or use the global option instead, until Photoswipe v5 is implemented, which doesn't need this container anymore.
Comment #4
anybodyAs the current error message is not very clear, let's at least add a better error message for now.
Comment #6
anybodyLet's merge this improved error message for now, until we have a solution or decide to not fix this and use v5.
Workaround for now: Enable the global option at /admin/config/media/photoswipe
Comment #7
thomas.frobieter@anybody There should be a hook to load the libraries, as you told me :P
Comment #8
anybodySo I think as long as the JS library needs this boilerplate code, but it's not added in the library by JS (which we intentionally don't do), there's no solution here.
For Photoswipe v4 aka module version 3.x the only solution for such custom cases is to call
\Drupal::service('photoswipe.assets_manager')->attach($attachments);in a hook or add the template code manually on the page before attaching
photoswipe/photoswipe.initlibrary.We won't fix this here for 3.x anymore.
In #3345294: Image Paragraph lightbox zoom misses to load photoswipe library I'll try to call
\Drupal::service('photoswipe.assets_manager')->attach($attachments);via hook.