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

Command icon 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

Anybody created an issue. See original summary.

anybody’s picture

The reason is, that if attaching the library via photoswipe/photoswipe.init the 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

\Drupal::service('photoswipe.assets_manager')->attach($attachments);

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.

anybody’s picture

Status: Active » Needs review
Related issues: +#3232070: [5.x] PhotoSwipe 5 Branch

As the current error message is not very clear, let's at least add a better error message for now.

  • Anybody committed ca1daee8 on 3.x
    Issue #3345311 by Anybody: Uncaught TypeError: a is undefined
    
anybody’s picture

Status: Needs review » Postponed

Let'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

thomas.frobieter’s picture

@anybody There should be a hook to load the libraries, as you told me :P

anybody’s picture

Status: Postponed » Closed (won't fix)

So 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.init library.

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.