I understand that the Photoswipe has some limited support for responsive images, but it would be good to get full compatibility with Drupal 8 responsive images.

Are there any plans?

Issue fork photoswipe-2980534

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

MrPaulDriver created an issue. See original summary.

mrpauldriver’s picture

Issue summary: View changes
anybody’s picture

Well as far as I can tell it works with responsive images. At least you can wrap an responsive image with a photoswipe link and it will be opened correctly. Or would you like to place the responsive image into the photoswipe box?

mrpauldriver’s picture

I think the term responsive can sometimes be confusing. Yes photoswipe images responsively scale to the viewport, but this is based on just a couple of predefined image styles. One for thumbnail and another for the main image.

From what I can tell it does not appear to support core responsive image functionality based on breakpoints and multiple image styles.

Some other image display modules, such as Flexslider and Slick have this option available, allowing us to send a small image to a mobile phone and a larger one to the desktop.

anybody’s picture

Thank you MrPaulDriver,

I can't speak for the other maintainers but I won't have the time to develop a patch for this. If you'd like to have this feature please provide a patch or pay someone who does it. Of course I'm willing to test and commit it once it has been successfully tested.

mrpauldriver’s picture

@Anybody - Thanks for the quick reply.

Photoswipe a great solution for touch devices and it is a shame that a responsive image option is not available at this time.

Unfortunately I don't have free budget for this currently, but maybe somebody will come along who wants to take the idea forward.

anybody’s picture

Same for me, thanks! So we'll leave this open.

anybody’s picture

Priority: Normal » Minor
nortmas’s picture

StatusFileSize
new9.96 KB

Here is the patch which provides additional field formatter to support Drupal Responsive image styles.
Please have a look, it was done pretty quick so most likely it requires some refactoring. But it works :)

nortmas’s picture

But this patch was done for the 8.x-2.x

nortmas’s picture

StatusFileSize
new20.31 KB

I'm sorry the patch in comment #9 is incorrect, please use this patch.

mrpauldriver’s picture

Thanks for working on this @nortmas

I am seeing a display formatter for Photoswipe Responsive which is what we want.

But when configuring the formatter, I see that responsive image types are available for the node image styles, but not for the Photoswipe image style. Assuming we want to build a swipeable responsive photo gallery, shouldn't this be the other way around?

I would expect to be using ordinary thumbnails for node image styles and a responsive image style for the Photoswipe images.

nortmas’s picture

Hi, no problem.

No, I don't think so. The responsive image styles are used for the image teasers to fit an adaptive design. The image teaser can be bigger or even has a different aspect ratio for the mobile/tablet view. That's why we need a responsive image style for the image teasers.

The "Photoswipe image style" is used for the full window view - which is already adoptive and design independent, isn't it? Usually, it's just an original image size.

However, I may assume that it can be necessary in some cases, let's say you upload an image for the retina display with a crazy resolution and you don't want it to be shown/loaded for the mobile devices because it doesn't make sense. In this case - yes.

But in my case I needed it to be for the only image teasers because we don't expect crazy images resolutions to be uploaded. So if you want to improve it a bit - would be great! ;)

mrpauldriver’s picture

With a name like Photoswipe, I think we can be sure that one intention is for viewing images on a hand held devices, hence the point of it supporting touch gestures.

Okay there are some large tablets around these days, but there are many more smaller screen smartphones.

Assuming that original images might be large megapixel photos, I think the benefits are clear for providing core responsive images, thus sending smaller images than the original to small screen devices.

anybody’s picture

@MrPaulDriver: I completely agree! It's no question that the module would benefit a lot from an implementation, someone just has to invest the time / money. I'll care for the review and commit, but I can't afford the time...

nikro’s picture

Hi there!

I like the patch, it gets the job done, however it needs to be able to handle galleries with 1 image.

+ if (!empty($items) && count($items) > 1) {

There's a related issue: https://www.drupal.org/project/photoswipe/issues/3030342 (which was committed, however as this formatter was inspired from the older one, it needs similar adjustments).

anybody’s picture

Please reroll the patch against the latest dev version and compare with #16.

iamdroid’s picture

StatusFileSize
new20.22 KB

Hi guys, thanks to everyone for your job and especially @nortmas for the great patch. I agree with @nortmas that responsive image support is most important for node images, not photoswipe ones. Photoswipe images should be big because it already supports responsiveness and zoom. Users should be able to see full images not depending on devices.

I updated the patch, removed hardcoded field name, and only first item definition. Also applied fix from #16.

steveoriol’s picture

Ok, the patch #18 works great for me, Thanks.

razunter’s picture

Tried patch #18, it doesn't seem to group multiple images to be able to switch between them in Photoswipe mode.

niklan’s picture

Version: 8.x-1.x-dev » 3.x-dev
StatusFileSize
new20.15 KB

Rerolled patch for 3.x-dev

anybody’s picture

Status: Active » Needs work

Thank you for the quick reroll :)

Needs work as of #20. Furthermore I really don't like the tons of copied code instead of abstraction and reuse, which will finally mess up this module. It's simple to do that, but not good coding style. If we want to get this patch committed in the future, this should be cleaned up, furthermore we should start writing tests for new functionality.

Thank you very much for your work anyway, I really appreciate this!

iamdroid’s picture

StatusFileSize
new20.17 KB

Updated patch for 3.x, replaced deprecated method entityManager().

g-brodiei’s picture

StatusFileSize
new20.18 KB
new572 bytes

Thanks to this outstanding patch, helped a lot upon our requirements!

Updated patch to allow "Node image style for first image" to take effect by its "responsive_image_style_id" format settings.

dinazaur’s picture

Assigned: Unassigned » dinazaur
Status: Needs work » Active
StatusFileSize
new29.28 KB
new42.54 KB

Refactored current implementation to eliminate tons of copy-paste code as was mentioned in #22.

dinazaur’s picture

StatusFileSize
new43.49 KB
new30.18 KB
rgeerolf’s picture

I can confirm #26 is working fine here on alpha0. As mentioned in #12 en #14, the option to set a responsive image style for the Photoswipe image would make this implementation complete. However this seems like a lot more work than the teaser images. Will try to investigate further.

widorski’s picture

The #26 worked very well for me on Drupal 8.9.14.
After core update on 8.9.15, the patch cannot apply. And responsive image styles are not more possible with photoswipe.

Thanks for your help!

steveoriol’s picture

The patch #26 applies very well to the version "3.0.0-alpha0",
but no longer on the new stable version "3.0.0"

anybody’s picture

Status: Active » Needs work

Ok so this needs a reroll?

As we have positive feedback I think afterwards and after some RTBCs again, we should consider to commit this. Any negative impacts yet?

anybody’s picture

PS: Could the reroll please happen as Issue Fork? :)

balis_m made their first commit to this issue’s fork.

balis_m’s picture

Status: Needs work » Needs review

The patch rerolled for 3.x-dev.

tim-diels’s picture

Tested the issue fork with Photoswipe 3.0 and Drupal 8.9.x and works as expected.
Looks like this also solves the problem from #3034421: Image Caption always shows label of field but have not tested this as the current website does not use that functionality.

steveoriol’s picture

No problem to patch the module within the composer.json with the "plain diff" :
https://git.drupalcode.org/project/photoswipe/-/merge_requests/8.diff
Works as expected with Photoswipe 3.0.0 and Drupal 9.2.3
Thank you

  • Anybody committed acf9c11 on 3.x authored by balis_m
    Issue #2980534 by dinazaur, nortmas, balis_m, iamdroid, g-brodiei,...
anybody’s picture

Status: Needs review » Fixed

Thank you for your hard work on this and positive feedback. Let's commit this to dev. Please help to test this before we create a new stable release.

batkor’s picture

I think. need reopen this issue.
And add this code (Example) to field formatter

 /**
   * {@inheritdoc}
   */
  public static function isApplicable(FieldDefinitionInterface $field_definition) {
    return \Drupal::service('module_handler')->moduleExists('responsive_image') ? parent::isApplicable($field_definition) : FALSE;
  }

We need check enabled "responsive image" module.

balis_m’s picture

Status: Fixed » Needs review

@batkor is right.

I' ve added an extra commit on "2980534-support-for-drupal" with the "responsive_image" module existence check.

anybody’s picture

Thank you @balis_m but I think the MR must be based on the latest dev where the changes were already committed. You first have to rebase locally. Currently it includes all changes again...

See here for details: https://git.drupalcode.org/project/photoswipe/-/merge_requests/12.patch

balis_m’s picture

@Anybody I'm sorry.

It must be ok now.

balis_m’s picture

@Anybody, I'm really sorry..

Finally, I' ve added the new commit on "2980534-support-for-drupal-applicable" and created a new merge request.

anybody’s picture

Status: Needs review » Fixed

@balis_m thank you :) Committed! Please try latest dev!

mrpauldriver’s picture

Wow. We eventually got there. Thanks to everyone who worked in this.

Wiktor7’s picture

I got the error:

Error: Call to a member function getFileUri() on null в Drupal\photoswipe\ImageDTO->__construct() (line 114 /var/www/anka/web/modules/contrib/photoswipe/src/ImageDTO.php)

This solved my problem:

ImageDTO.php

111 - ? ($this->item = $item->title)
112 - : (!empty($item->field_file_image_title_text[Language::LANGCODE_NOT_SPECIFIED]) && ($this->item = $item->field_file_image_title_text[Language::LANGCODE_NOT_SPECIFIED][0]['value']));

111 + ? ($this->title = $item->title)
112 + : (!empty($item->field_file_image_title_text[Language::LANGCODE_NOT_SPECIFIED]) && ($this->title = $item->field_file_image_title_text[Language::LANGCODE_NOT_SPECIFIED][0]['value']));

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

marcoka’s picture

I have the same error as #49. So this should be reopened and the issue discussed. I can see, using xdebug, why that error will be thrown.
I will try what #49 did next in the code.

That part #49 posted is not the problem. What i did is set the responsive formatter to a display mode

The error is thrown because $this->item->entity is NULL in my case. Does #49 use layout manage? I do because its one of the best new drupal features. I think this code works only on a normal page that doesnt use layout manager.

balis_m’s picture

I've fixed this issue here Image alt/title tag as photoswipe caption not working in entity reference fields

Could you please check that it works?

marcoka’s picture

A very nice, faster then i can send my edited comment. Thank you. I will check your patch right now and report back.

chucksimply’s picture

Can we confirm whether or not this fix is in 3.0.1. As the above patch (#24) applies and works on 3.0.0... but won't apply to 3.0.1

agoradesign’s picture

It is in 3.0.1 - and it's easy to find out. Just compare the dates. #37 shows the commit, which happened on September 1st. 3.0.0 was released in June 2021. 3.0.1 was released shortly in February

anybody’s picture

Thanks @agoradesign, confirming #55! It's in 3.0.1 :)

chucksimply’s picture

Thank you!

marcoka’s picture

With the latest core 9.3.12 the repsonsive formatter has problems. The normal one does not.
#3276924: Wrong image paths with photoswipe responsive formatter