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've just noticed that it's not possible to select a "Responsive image style" as the "Colorbox image style" when configuring this module. Is that because this module relies on the use of a formatter (as does D8 core's Responsive image module)? It would be great to get this working.
Comment | File | Size | Author |
---|---|---|---|
#69 | interdiff-68-69.diff | 5.19 KB | jurgenhaas |
#69 | colorbox-responsive-image-2808883-69.patch | 29.13 KB | jurgenhaas |
#68 | interdiff-2808883-64-68.txt | 9.34 KB | huzooka |
#68 | colorbox-responsive-image-2808883-68.patch | 30.93 KB | huzooka |
#64 | colorbox-responsive-image-2808883-64.patch | 29.8 KB | interdruper |
Issue fork colorbox-2808883
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:
- 2808883-support-responsive-image changes, plain diff MR !13
Comments
Comment #2
oana.hulpoi CreditAttribution: oana.hulpoi as a volunteer commentedHey, Do we have any news regarding this feature request?
Of course, we can always adopt a custom and personal solution to achieve this. But, as long as responsive images are in core, I think that it would be nice to have a colorbox module built-in solution...
Thanks!
Comment #3
Anonymous (not verified) CreditAttribution: Anonymous at Cheeky Monkey Media commentedComment #4
rolfmeijer CreditAttribution: rolfmeijer at Dutch Open Projects commentedI had a go with it this weekend, but unfortunately could not finish it and I won’t be able to work on it the coming weeks. I post it here, maybe it is useful as a starting point, otherwise I will look into it later again. I made a separate Field Formatter, basically combining the Colorbox Formatter with the Responsive Image Formatter form core.
A few remarks:
Comment #5
Anonymous (not verified) CreditAttribution: Anonymous at Cheeky Monkey Media commented@rolfmeijer - great start. I had been working on something similar, but was having a few little hiccups. Your patch has gotten me past those.
After getting a little further along, I'm starting to realize, we need to make a few decisions. Since in 8.x, colorbox inline is not a default option, we can't use a responsive image for the actual colorbox content, since you would need a singular image url.
What we could do is allow responsive image style selection for the content image, and set up the "for Colorbox" field only have "None (original image)". And then add functionality in colorbox_inline to allow responsive image styles in the "for Colorbox" field, and then in the template, render out the responsive image in a hidden container inline, and link to the the image's container.
Comment #6
Anonymous (not verified) CreditAttribution: Anonymous at Cheeky Monkey Media commentedI've got things at a more usable state.
As I mentioned in my previous comment, colorbox_inline will need to be used if one wants to use responsive images in the colorbox as standalone, it is really only possible to use them for the node/trigger images.
Comment #7
MrPaulDriver CreditAttribution: MrPaulDriver commentedIt would be great to see this finished off.
Comment #8
LonitaD CreditAttribution: LonitaD commentedI would love if we could get this working. When I tried testing it by selecting the new formatter in the display settings, I got the following PHP error:
Error: Call to a member function label() on null in /modules/colorbox/src/Plugin/Field/FieldFormatter/ColorboxResponsiveFormatter.php on line 270
The loading spinner appeared next to the formatter selector but the settings didn't load and I got an AJAX error and it kept spinning.
Comment #9
auxiliaryjoel CreditAttribution: auxiliaryjoel commentedHi I was just wondering if there was any more progress on this?
Comment #10
markdcOur company is looking for this. If funding is needed, send me a message.
Comment #11
Neslee Canil PintoPatch failed to apply
Comment #12
toasdt CreditAttribution: toasdt commentedThis patch should
– apply (both to the latest commit d2fa6de5 and version 8.x-1.6) and work and
– solve the issue in comment #8.
– Additionally, it's adapted to some changes in the module code since the first patches three years ago, like coding standards or naming conventions. For example, the names and structure of the Colorbox Responsive formatter are now closer to the Colorbox formatter and/or the Responsive Image formatter (in core's responsive_image module).
But...
– I haven't tested the colorbox_inline integration yet, which is necessary for responsive images in the Colorbox popup, see comments #5 and #6, in particular the preparations for that in colorbox.theme.inc (look for the $colorbox_inline variable). By now, the "Colorbox Responsive" formatter only affects the "content image" (the preview in the content).
– The first-image options is still left out (as in #4).
Comment #13
RedTop CreditAttribution: RedTop commentedThanks for this, I'll get onto this now. :)
Edit:
Colorbox Inline functionality is not yet functional, a modal opens but collapses. I am on Drupal 8.8.6 and patched against 8.x-dev d2fa6de5, using the Colorbox Responsive Formatter on Media Image entities.
After uninstalling Colorbox Inline the modal works but is obviously the full image. Note that the Media Entity Manage Display form also shows the option to set the 'Colorbox responsive image style' when Colorbox Inline is not enabled. The availability of this should probably be dependent on Colorbox Inline being available or not.
Regardless, thanks! It's a big step forward. :)
I had started working on this as well so I will compare code and see if there is something useful left.
Comment #14
jurgenhaasTried this with media image from core and it works great for responsive content image style. For the colorbox responsive image style, it doesn't seem to work, I always get the original image being displayed in the colorbox.
Comment #15
J-LeeShort review from patch from #12.
I notice an issue with the fallback img tag. There are some attributes (e.g. alt tag value) missing.
The $variables['responsive_image']['#attributes'] are build in template_preprocess_responsive_image_formatter() in responsive_image.module with alt, title etc. In the patch they are taken from $variables['item_attributes'] or an empty array, which seems to be wrong.
Comment #16
J-LeeReroll of #12 with the fixed issue from #15.
Still needs work with the other issues.
Comment #17
J-LeeTests are green but putting back to needs work as of #13 and #14.
Comment #18
J-LeeAfter thinking about #14 I found some more things, we should think about.
Comment #19
4kant CreditAttribution: 4kant commentedPatch #16 doesn´t apply to latest colorbox release 8.x-1.7 or latest dev.
Comment #20
Suresh Prabhu Parkala CreditAttribution: Suresh Prabhu Parkala at Specbee commentedIt's just a re-roll.
Comment #21
4kant CreditAttribution: 4kant commentedThanks - patch applies to 8.x-1.7.
Cleared the cache...
There is no "Colorbox Responsive" as an image formatter.
Comment #22
Johan den Hollander CreditAttribution: Johan den Hollander commentedTested the #20 patch. The Colorbox responsive option became available only after clearing the caches.
It works well!
Comment #23
arturopanettaI tested patch #20.
In the backend, the "Colorbox responsive" option works fine.
The output of "Responsive content image style" works correctly.
The output of "Colorbox responsive image style" does not work correctly, the original image is returned in any breakpoint.
Comment #24
Johan den Hollander CreditAttribution: Johan den Hollander commentedAs mentioned before by @jurgenhaas and @arturopanetta the Cololorbox responsive image style does not work at all.
There are some preparations done, but the code is commented out.
And so the code in else runs:
Which gives us the original image.
This if fine for me, for now as I want to show the original image or at least a large one to the users. But it is not responsive. And so this issue needs work!
Comment #25
Johan den Hollander CreditAttribution: Johan den Hollander commentedAlways showing the original image in the colorbox popup may not be the best solution after all. Users having uploaded stock images of many MB's etc...
So I tried my luck copying and pasting some code and now found a (temporarily) solution that makes it possible to select the imagestyle that is used in the colorbox. It is not a responsive image, but just directly picking the imagestyle.
This is achieved by adding the colorbox_image_style to the settings form, and also to the output.
The chosen imagestyle is then also exported as a dependency when doing a config export.
The summary of the settingsform also reflects this setting:
Please review, I am not thinking this is the final solution. Just trying to get this issue moving and offering a workaround to make this functionality more usable.
Comment #26
Johan den Hollander CreditAttribution: Johan den Hollander commentedComment #27
Johan den Hollander CreditAttribution: Johan den Hollander commentedReupload, #25 patch dit not apply correctly. Should be ok now.
Comment #28
frankdesign CreditAttribution: frankdesign commentedPatch at #27 work perfectly for the Responsive Image Style setting for the image in the page content.
But the setting for 'Responsive image style for Colorbox' doesn't seem to do anything. The image style used for the Colorbox image uses the setting 'Image style for Colorbox' setting. In my use case, I want the original image to open in the Colorbox, so by setting 'Image style for Colorbox' to 'None (original image)' works perfectly.
Thanks
F
Comment #29
J-LeeReroll for colorbox 1.8. Needs review because of SA-CONTRIB-2022-007.
Comment #30
Johan den Hollander CreditAttribution: Johan den Hollander commentedThe #29 patch applies to colorbox 1.8.0 and works the same way as #27.
Comment #31
4kant CreditAttribution: 4kant commentedDid someone get colorbox_inline to work?
Colorbox_responsive images work in general, but with colorbox_inline it´s still the same as for #13.
Thanks!
Comment #32
jurgenhaasUnfortunately, patch from #29 doesn't apply to the latest release anymore as some of the changes have already been made to the official code base. Just couldn't figured out which ones.
Comment #35
s_leu CreditAttribution: s_leu at Tag1 Consulting commentedRe-rolled the patch in a MR against 8.x-1.x . Also implemented the method
FormatterInterface::isApplicable()
in the new formatter plugin to prevent confusion/errors when selecting the formatter if the responsive_image module isn't enabled at all.Comment #36
jurgenhaasThis is looking good again. Thanks a lot @s_leu
Comment #37
Johan den Hollander CreditAttribution: Johan den Hollander commentedTHe #34 works well. Thanks!
Comment #38
Nathan Tsai CreditAttribution: Nathan Tsai at Alberni Design commentedWanting to get WebP images enabled for Colorbox.
Looking forward to seeing this patch committed :)
Comment #39
PROMESI patched the current version 8.x-1.10 but no Colorbox image appears when clicking on a picture.
When will this issue be working? I need it for three sites.
Comment #40
PROMESI am sorry. I made a mistake. Patch 29 works as expected. Like #38 I like to have the popup images also in WebP format.
Thanks for a great module and this patch.
Comment #41
J-LeeI think, we need a reroll against the latest 2.0 branch.
Comment #42
J-LeeComment #43
ArantxioRe-rolled the patch for the new 2.0.x branch, some code just seemed to overlap. so I just manually checked and implemented the old code.
Needs to be completely verified before use, as this is my first time making a patch like this.
Patch applies, and passes the tests, but it needs some refinement for coding standards, as some indentations has 4 spaces instead of 2.
Comment #44
ArantxioAs stated in #43 I had issues with the indentations, i have reformatted it and made a new patch.
Comment #45
ArantxioThe patch in #44 used tabs instead of spaces, which is also bad practice. reformatted it again.
Comment #46
ArantxioI changed some more coding standards and also made reroll_diff so you can see the changes since the MR_13 in comment #34
Comment #47
VrancjeTested #46 and works on 9.3.22! Thanks a lot!
Comment #48
Qusai Taha CreditAttribution: Qusai Taha at Vardot commentedRe-roll patch for 8.x-1.10
Comment #49
VVS CreditAttribution: VVS commented#46
Comment #50
surrim CreditAttribution: surrim commentedTested colorbox-responsive-image-2808883-46.patch and does not work as espected with Colorbox 2.0.x / Drupal 10.0.0.
The Colorbox Responsive field configuartion looks like that:
Briefly:
Included thumbnail image code:
Included Colorbox image code:
I think Image style for Colorbox is obsolete here (only for non-responsive Colorbox) and Responsive image style for Colorbox should be used instead.
Comment #51
PROMESThe line (#279 in my patch):
if (((strpos($colorbox_style, 'colorbox/example') !== FALSE) || $config->get('colorbox_caption_trim')) && (mb_strlen($caption) > $trim_length)) {
gives this message:
Deprecated function: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in _colorbox_formatter_get_caption()
Comment #52
astringer CreditAttribution: astringer commentedI concur with #50 and add that the image style formatter also does not work as expect for Colorbox 2.0.x / Drupal 9.5. See #50 for details.
Can we change this to Needs Work? To warn folks that it doesn't really work in the way you'd think.
Also it would be great to get this working, I read through this whole thread and I'm wondering if these same issues still exist. (A single URL is required for the color box image). I'm happy to help if anyone has ideas on how to approach. Would be nice to not have to serve a single large colorbox image to everyone.
Comment #53
KlemenDEV CreditAttribution: KlemenDEV as a volunteer and at Pylo commentedComment #54
KlemenDEV CreditAttribution: KlemenDEV as a volunteer and at Pylo commentedIs anyone working on this? I can help with active testing as this feature is quite important on our website.
Comment #55
J-Lee@KlemenDEV: I don't think anyone is actively working on it.
The MR is outdated and the patch from #46 is the last state from which it should be continued.
For the responsive image style for content (responsive thumbnail image) the lazy loading option is also missing.
Comment #56
J-Lee$item->title
could be NULL, so a deprecation will be triggert: "Deprecated function: mb_strlen(): Passing null to parameter #1 ($string) of type string is deprecated". Maybe change toif (mb_strlen($item->title ?? '') != 0) {
Comment #57
J-LeeIn summary, we should continue with patch #46 and respect the reviews from #50, #51 and #56.
Comment #58
J-LeeI have updated MR to #46 and fixed #51 and #56.
But there are more issues e.g.:
$colorbox_style = $config->get('colorbox_style')
But there is no config 'colorbox_style'. Maybe it should 'custom.sytle'$config->get('colorbox_caption_trim_length')
-> Should be 'advanced.caption_trim_length'Comment #59
J-LeeThe points from #58 are not relevant here.
But I think we should split this topic into several issues because there are different functions.
The original request was that Colorbox should be compatible with a responsive image formatter. We should focus on that and merge that first.
Another feature that doesn't work (cleanly) is to display a responsive image inside Colorbox. We should address this in a separate followup issue.
Perhaps the maintainers can comment briefly on the strategy?
Comment #60
J-LeeI cannot change the target branch at the MR to the 2.0 branch 😞
Comment #61
J-LeeAttached the new patch file.
Comment #63
s_leu CreditAttribution: s_leu at Tag1 Consulting commentedRe-rolled this once more against the new 2.0.x branch which the patch in #61 doesn't apply any more because the README.txt is now README.md. So this new patch just moves the README part into the .md file
Comment #64
interdruper CreditAttribution: interdruper at Interdruper commentedPatch #63 works fine, but a deprecated notice is triggered under PHP 8.2:
Deprecated function: Creation of dynamic property Drupal\colorbox\Plugin\Field\FieldFormatter\ColorboxResponsiveFormatter::$attachment is deprecated in Drupal\colorbox\Plugin\Field\FieldFormatter\ColorboxResponsiveFormatter->__construct() (line 96 of /colorbox/src/Plugin/Field/FieldFormatter/ColorboxResponsiveFormatter.php)
This patch for 2.0.x fixes the issue.
Comment #65
luenemannNo complete review!
The patch should use the service
colorbox.gallery_id_generator
introduced in #2935266: Make gallery id generation function independent., released in 8.x-1.7 on 5 March 2021Comment #66
luenemannSorry, service
colorbox.gallery_id_generator
is in use.But
use Drupal\Component\Utility\Crypt;
is missing:Comment #67
candelas CreditAttribution: candelas commentedThanks @interdruper, patch in #64 works.
I hope soon it will be part of the great Colorbox module.
Comment #68
huzookaContinued the patch in #64:
Comment #69
jurgenhaasRe-rolled for the latest 2.0.x changes.
Comment #70
4kant CreditAttribution: 4kant commented#69 applied cleanly in Drupal 10.2.5 and latest dev-Version of colorbox.
And it works well.
Thanks!
Comment #71
paulmckibbenUpdating issue credits.
Comment #72
paulmckibbenThanks to everyone who has contributed to this patch and gotten it to where it is so far. I just see a couple small problems:
1. With DOMPurify enabled, HTML in captions still get converted to text.
2. colorbox-responsive-formatter.html.twig should use the same aria attributes that colorbox-formatter.html.twig has.Edit: actually, on deeper inspection, colorbox-formatter.html.twig uses aria attributes incorrectly, so disregard item 2 above.
Comment #74
paulmckibbenI fixed the problem with DOMPurify - I updated ColorboxResponsiveFormatter to load DOMPurify if it exists. Thanks to everyone for your work on this patch. It is committed!