Uncaught TypeError: a is undefined

Created on 1 March 2023, almost 2 years ago
Updated 2 March 2023, almost 2 years ago

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

🐛 Bug report
Status

Closed: won't fix

Version

3.0

Component

Code

Created by

🇩🇪Germany Anybody Porta Westfalica

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @Anybody
  • 🇩🇪Germany Anybody Porta Westfalica

    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 ...

  • @anybody opened merge request.
  • Status changed to Needs review almost 2 years ago
  • 🇩🇪Germany Anybody Porta Westfalica

    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
      
  • Status changed to Postponed almost 2 years ago
  • 🇩🇪Germany Anybody Porta Westfalica

    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

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

  • Status changed to Closed: won't fix almost 2 years ago
  • 🇩🇪Germany Anybody Porta Westfalica

    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 🐛 Image Paragraph lightbox zoom misses to load photoswipe library Fixed I'll try to call
    \Drupal::service('photoswipe.assets_manager')->attach($attachments);
    via hook.

Production build 0.71.5 2024