Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I try to use PhotoSwipe formatter with media in views and get the error from the original - there's a bunch more in my error but that is the first line.
Error: Call to undefined method Drupal\media\Entity\Media::getFileUri() в template_preprocess_photoswipe_image_formatter()
Is there any solution to this?
Comment | File | Size | Author |
---|---|---|---|
#15 | Screen Shot 2020-03-31 at 8.05.37 PM.png | 145.99 KB | chucksimply |
Screenshot at 2019-03-14 13-31-16.png | 73.67 KB | ivnish |
Comments
Comment #2
ergophobe CreditAttribution: ergophobe as a volunteer commentedI think this meets the criteria for a major bug since Photoswipe is unusable with Media and Views, which is part of the Photoswipe functionality.
Doing some digging, but not close to figuring this out. The error message is the same as in the original issue report.
Note that the line number is not the same as in the distro, because I have some debug code in there.
Setting some breakpoints and examining code execution, there are a number of things that fail prior to that.
When I inspect $item->entity the type is Drupal\media\Entity\Media, so both parts of the OR statement fail.
Also, $settings['photoswipe_reference_image_field'] is an empty string. So that is not getting passed, the the last part of the conditional fails as well.
The other settings for image styles and captions are fine.
Comment #3
viappidu CreditAttribution: viappidu as a volunteer commentedI don't use photoswipe in views though the patch I created in the related layout builder issue solved my problems. Please check if this works also for this issue
Comment #4
viappidu CreditAttribution: viappidu as a volunteer commentedPatch added to the related issue at #4 please review
Comment #5
ivnish CreditAttribution: ivnish commentedPatch doesn't solve the problem.
Comment #6
ivnish CreditAttribution: ivnish commenteddel
Comment #7
chucksimply CreditAttribution: chucksimply commentedSame issue and error here.... and patch from #4 doesn't work. @ivnish, did you find a solution or work around?
Comment #8
chucksimply CreditAttribution: chucksimply commentedComment #9
Burlyn84 CreditAttribution: Burlyn84 commentedI am facing the exact same error.
Comment #10
calebyoder CreditAttribution: calebyoder commentedYes, we have this site that says "The website encountered an unexpected error. Please try again later." at the bottom of the pages and when I try to run cron it shows a blank white page with "The website encountered an unexpected error. Please try again later."
In the error log I am getting this:
I tried implementing the patch referred to above in comment #3 (https://www.drupal.org/project/photoswipe/issues/3040117#comment-13226403) but doesn't seem to fix it.
Anyone have any idea what the issue is and how to fix?
Thanks!
Comment #11
chucksimply CreditAttribution: chucksimply commentedLooks to be related to this issue (Support for Media and Entity References) which is deemed as fixed. But based on my testing in Drupal 8.8, it should be reopened. See my feedback here. Hopefully, we can get some progress on one of these threads.
Comment #12
chucksimply CreditAttribution: chucksimply commentedComment #13
No Sssweat CreditAttribution: No Sssweat commentedSeems like the fix has not been committed to the stable version.
Please try with the 2.x-dev version version, as this other comment indicates and let us know how it goes.
Comment #14
Burlyn84 CreditAttribution: Burlyn84 commentedDo you really mean that? According to the module page that was released in 2018.
If that is what it takes, we can do that, but seems kind of strange to have to go back that far to get a working version.
Comment #15
chucksimply CreditAttribution: chucksimply commentedTried 2.x-dev with Drupal 8.8. Bug still exists. I believe the issue is that the "image field of the referenced entity" field doesn't contain the media image field as it should (In a View when selecting the photoswipe formatter... see attached screenshot). Then saving without a media image field selected and viewing that views page throws this above error?
Comment #16
chucksimply CreditAttribution: chucksimply commentedOkay, found a temporary workaround. As the original issue shows, the "image field of the referenced entity" doesn't have a value, and when saved without a value selected, the above error shows.
The problem is rooted on line 161 of /src/Plugin/Field/FieldFormatter/PhotoswipeFieldFormatter.php...
$target_bundles = $this->fieldDefinition->getSetting('handler_settings')['target_bundles'];
The handler_settings array is empty within a view.. so $target_bundles is null.
If you include...
... directly after line 161 (replacing "image" with your media bundle) the "image field of the referenced entity" will populate correctly. I know this is a module hack and not a long term solution, but hopefully, someone else can take this info and create a more dynamic solution and patch.
Comment #17
extect CreditAttribution: extect commentedInstead of including the media reference field in your view, try to setup a relationship to the media entity and then include the image field directly to make photoswipe work.
Comment #18
chucksimply CreditAttribution: chucksimply commentedThanks @extect, that's a work around, but is limiting for many reasons. It's still true that this is a bug, and deserves an actual code fix.
Comment #19
ThibThe tip of @extect is a good alternative that I use
Comment #20
AnybodyCleanup: Closing outdated 8.x-2.x branch issues.
Please try with the latest 3.x version if the issue persists. If yes, reopen the issue and switch the issue version to 3.x with a clear description how to reproduce the issue in 3.x
Thank you! :)