Support Responsive Image module in D8

Created on 29 September 2016, about 8 years ago
Updated 6 May 2024, 8 months ago

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.

โœจ Feature request
Status

Fixed

Version

2.0

Component

Code

Created by

๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom dddbbb

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • ๐Ÿ‡ธ๐Ÿ‡ฎSlovenia KlemenDEV

    Is anyone working on this? I can help with active testing as this feature is quite important on our website.

  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany J-Lee ๐Ÿ‡ฉ๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ
    @@ -139,6 +82,190 @@ function template_preprocess_colorbox_formatter(&$variables) {
         $variables['url'] = $file_url_generator->generateAbsoluteString($image_uri);
       }
    
    +  if (!empty($variables['responsive_image'])) {
    +    $attributes = [];
    +    // Do not output an empty 'title' attribute.
    +    if (mb_strlen($item->title) != 0) {
    +      $variables['responsive_image']['#title'] = $item->title;
    +      $data_cbox_img_attrs['title'] = '"title":"' . $item->title . '"';
    

    $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 to if (mb_strlen($item->title ?? '') != 0) {

  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany J-Lee ๐Ÿ‡ฉ๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    In summary, we should continue with patch #46 โœจ Support Responsive Image module in D8 Needs work and respect the reviews from #50 โœจ Support Responsive Image module in D8 Needs work , #51 โœจ Support Responsive Image module in D8 Needs work and #56 โœจ Support Responsive Image module in D8 Needs work .

  • Assigned to J-Lee
  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany J-Lee ๐Ÿ‡ฉ๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    I 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'
    • Same with $config->get('colorbox_caption_trim_length') -> Should be 'advanced.caption_trim_length'
    • ... there are more ...
  • Issue was unassigned.
  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany J-Lee ๐Ÿ‡ฉ๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    The points from #58 are not relevant here.

    But I think we should split this topic into several points 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?

  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany J-Lee ๐Ÿ‡ฉ๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    I cannot change the target branch at the MR to the 2.0 branch ๐Ÿ˜ž

  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany J-Lee ๐Ÿ‡ฉ๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    Attached the new patch file.

  • Status changed to Needs review over 1 year ago
  • Open in Jenkins โ†’ Open on Drupal.org โ†’
    Core: 10.1.x + Environment: PHP 8.1 & MySQL 8
    last update over 1 year ago
    4 pass
  • Re-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

  • Open in Jenkins โ†’ Open on Drupal.org โ†’
    Core: 10.1.x + Environment: PHP 8.1 & MySQL 8
    last update over 1 year ago
    4 pass
  • ๐Ÿ‡ช๐Ÿ‡ธSpain interdruper

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

  • Status changed to Needs work over 1 year ago
  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany luenemann Sรผdbaden, Germany

    No 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 2021

  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany luenemann Sรผdbaden, Germany

    Sorry, service colorbox.gallery_id_generator is in use.

    But use Drupal\Component\Utility\Crypt; is missing:

    +++ b/colorbox.module
    index 6b216e2..23c9a87 100644
    --- a/colorbox.theme.inc
    
    --- a/colorbox.theme.inc
    +++ b/colorbox.theme.inc
    
    +++ b/colorbox.theme.inc
    +++ b/colorbox.theme.inc
    @@ -8,6 +8,7 @@
    
    @@ -8,6 +8,7 @@
     use Drupal\file\Entity\File;
     use Drupal\image\Entity\ImageStyle;
     use Drupal\Component\Utility\Xss;
    +use Drupal\responsive_image\Entity\ResponsiveImageStyle;
     
    
    @@ -139,6 +82,190 @@ function template_preprocess_colorbox_formatter(&$variables) {
    +    $image_id = $entity_id . '-' . Crypt::randomBytesBase64(8);
    
  • ๐Ÿ‡ช๐Ÿ‡ธSpain candelas

    Thanks @interdruper, patch in #64 works.
    I hope soon it will be part of the great Colorbox module.

  • Status changed to Needs review 10 months ago
  • Open in Jenkins โ†’ Open on Drupal.org โ†’
    Core: 10.2.x + Environment: PHP 8.1 & MySQL 8
    last update 10 months ago
    4 pass
  • ๐Ÿ‡ญ๐Ÿ‡บHungary huzooka Hungary ๐Ÿ‡ญ๐Ÿ‡บ๐Ÿ‡ช๐Ÿ‡บ

    Continued the patch in #64:

    • Fixed CS of the new formatter
    • Addressed #66
    • Added schema for the new formatter.
  • Open in Jenkins โ†’ Open on Drupal.org โ†’
    Core: 10.2.x + Environment: PHP 8.1 & MySQL 8
    last update 9 months ago
    Patch Failed to Apply
  • Open in Jenkins โ†’ Open on Drupal.org โ†’
    Core: 10.2.x + Environment: PHP 8.1 & MySQL 8
    last update 9 months ago
    4 pass
  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany jurgenhaas Gottmadingen

    Re-rolled for the latest 2.0.x changes.

  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany 4kant

    #69 applied cleanly in Drupal 10.2.5 and latest dev-Version of colorbox.
    And it works well.
    Thanks!

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States paulmckibben Atlanta, GA

    Updating issue credits.

  • Status changed to Needs work 8 months ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States paulmckibben Atlanta, GA

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

  • Status changed to Fixed 8 months ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States paulmckibben Atlanta, GA

    I 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!

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

Production build 0.71.5 2024