Hey, thank's for this awesome module.
There is a minor issue where the html is printed different when there is one image and when there is multiple images.
When there is one image the root div is the field name and the inner div is photoswipe-gallery;
<div class="field field--name-field-myfield field--type-image field--label-hidden field__items">
<div class="field__item">
<span class="photoswipe-gallery photoswipe-gallery--fallback-wrapper" data-once="photoswipe">
<a href="http://local.blabla/sites/default/files/styles/original/public/2023-09/gen9A8D.tmp.jpg.webp?itok=3ZPTtNXj" class="photoswipe" data-pswp-width="438" data-pswp-height="399" data-once="photoswipePrepareGalleries">
<img src="/sites/default/files/styles/landscape/public/2023-09/gen9A8D.tmp.jpg.webp?itok=v0o7ki-4" width="1000" height="560" alt="Eum mauris tation." title="Cogo loquor utinam." loading="lazy" class="image-style-landscape">
</a>
</span>
</div>
</div>But when there are multiple images the html structure changes and the parent becomes photoswipe-gallery and field name becomes the child div.
<div class="photoswipe-gallery" data-once="photoswipe">
<div class="field field--name-field-myfield field--type-image field--label-hidden field__items">
<div class="field__item">
<a href="http://local.blabla/sites/default/files/styles/original/public/2023-09/gen9A3C.tmp.png.webp?itok=5U5qcFjR" class="photoswipe" data-pswp-width="364" data-pswp-height="553" data-once="photoswipePrepareGalleries"><img src="/sites/default/files/styles/landscape/public/2023-09/gen9A3C.tmp.png.webp?itok=VSyZkiPH" width="1000" height="560" alt="Facilisis humo pne" title="Abico diam incassum " loading="lazy" class="image-style-landscape"></a>
</div>
<div class="field__item">
<a href="http://local.blabla/sites/default/files/styles/original/public/2023-09/gen9B6C.tmp.jpeg.webp?itok=vH-X6tc0" class="photoswipe" data-pswp-width="482" data-pswp-height="226" data-once="photoswipePrepareGalleries"><img src="/sites/default/files/styles/landscape/public/2023-09/gen9B6C.tmp.jpeg.webp?itok=WVDq2IjX" width="1000" height="560" alt="Exputo quidem suscipere. Acsi " title="Camur cogo hendrerit paratus" loading="lazy" class="image-style-landscape"></a>
</div>
<div class="field__item">
<a href="http://local.blabla/sites/default/files/styles/original/public/2023-09/gen9A3C.tmp.png.webp?itok=5U5qcFjR" class="photoswipe" data-pswp-width="364" data-pswp-height="553" data-once="photoswipePrepareGalleries"><img src="/sites/default/files/styles/landscape/public/2023-09/gen9A3C.tmp.png.webp?itok=VSyZkiPH" width="1000" height="560" alt="Hendrerit quidne ut." title="Aliquam huic si sit zelus." loading="lazy" class="image-style-landscape"></a>
</div>
</div>
</div>The correct approach would be IMHO the one where the field name is root. like the other fields right beside them.
| Comment | File | Size | Author |
|---|---|---|---|
| #11 | 2023-09-06 13_03_10-asfdsdafasdf _ Drush Site-Install.png | 39.61 KB | grevil |
Issue fork photoswipe-3384849
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
rgnyldz commentedComment #3
grevil commentedThanks for the issue report! I agree. 👍
Comment #4
anybody@Grevil: Let's please fix this and prepare a MR. I think it's important to solve this as early as possible, before many people are using / styling the structures.
Is this something we need to solve in this module or is this from the pswp library? Eventually let @thomas.frobieter also take a look for the right solution.
Comment #5
grevil commentedThis is probably linked to the JS setting the fallback wrapper, have a more concise look at the wrapper:
<span class="photoswipe-gallery photoswipe-gallery--fallback-wrapper" data-once="photoswipe">vs.
<div class="photoswipe-gallery" data-once="photoswipe">I'll get to it, as soon, as I can!
Comment #6
grevil commentedThis isn't easily done. Inside "/src/Plugin/Field/FieldFormatter/PhotoswipeFieldFormatter.php", we have the following code, which causes this issue:
Prefixing "elements" unfortunately means prefixing the entire field, for some reason...
Meaning we probably need to move the entire logic inside our js, which ACTUALLY makes way more sense, since if we are using multiple images on a template using our twig method or the global photoswipe option, and no wrapper is manually set, each image will be wrapped independently!EDIT: Upon further investigation, unfortunately, wrapping it on the php site only makes sense, since this issue is specific to the field formatter, any other a.photoswipe link needs to get wrapped individually (as a fallback of course), since we can't tell if multiple a.photoswipe links belong to one gallery or not, outside the field context.
Comment #7
anybodyYeah this was a very very large topic in the past... we shouldn't make too quick changes here. Now I also see the key difference: It's the fallback gallery wrapper vs. the intended gallery wrapper.
As this is expected behavior for reasons, I don't rate this as bug anymore, instead we should discuss how to unify the functionality, by for example only setting classes, but not adding wrappers. We need to discuss this personally in the team.
Switching to feature request for further discussions.
Comment #8
thomas.frobieterWhy don't we just add the class to the field attributes then?
If the field wrapper is removed by the theme for whatever reason, the JS fallback kicks in.
Comment #9
thomas.frobieterComment #10
anybodyIt's not that simple. Many edge cases need to be considered, we shouldn't glitch back into the tales we were in before the current solution. No quick shots please, but of course suggestions like this are welcome for discussion.
Comment #11
grevil commentedI tinkered around a bit in the formatter and the reason why the whole field is prefixed, is because inside FormatterBase's "view()" method, the items from "viewElements" are simply merged with the "field" theme defintion:
Leading to an incorrect hierarchy codewise:

(The array entries 0 and 1 contain our "photoswipe_image_formatter" theme items and are therfore on the same level with the "field" theme)
I guess, this could be seen as a core bug, but on average this isn't a problem in 99% of all cases.
Comment #12
grevil commentedSo my solution would be to create a separate 'photoswipe-image-formatter-gallery-wrapper' template, in which we define the gallery wrapper span / div and pass our "photoswipe-image-formatter" items into and display them.
This way we have a formatter specific solution which is really nice and clean and people can also hook into the gallery wrapper template and inject their own HTML if needed!
Comment #14
grevil commentedI created a first MR, to show my approach. It's not perfect yet, currently I can only add the wrapper under the field-item or around the field. Not in between, so this still needs work (and discussion).
Comment #15
grevil commentedAll done, please review!
Comment #16
grevil commentedI'll adjust the tests tomorrow.
Comment #17
anybodyThanks @Grevil, Code changes LGTM. For each broken test please manually check the new result is *really* correct. There's still a risk left that we forgot something or special things happen. We should use this chance :)
@thomas.frobieter should afterwards test the dev version, to be sure nothing is broken, before we tag a new release.
Comment #18
anybodyComment #19
anybody@Grevil and @thomas.frobieter I think we should try to get this fixed ASAP as the code changes will be kind of BC. This means we need at least a 5.1.0 version then. Better to fix it earlier than leter.
Comment #20
grevil commentedMight take a bit, since I can not run photoswipe js tests locally.
Comment #21
grevil commentedAll adjusted accordingly! Tests with two media/image fields vs. two one field with multiple pictures COULD be refined, but they are fine as is (there is a line checking for two gallery wrappers [2 fields] and for one gallery wrapper [1 field 2 pictures]).
This can be reviewed!
Comment #22
grevil commentedComment #23
anybodyChanges LGTM. BC notes above. Think there's no way around it.
Comment #24
anybodyComment #26
rgnyldz commentedI can confirm that the html structure is better and consistant now with the new version. Appreciate the work guys, thanks a lot ;)