Caption calculation has a somewhat complex logic on it and it lives in a theme function "_glightbox_formatter_get_caption", it would be more flexible if we had a service for it so anyone can really implement/decorate their own captions without adding too much burden to this module, i.e. if the video one I've implemented here https://www.drupal.org/project/glightbox_media_video/issues/3492655 had to duplicate this code.

Comments

pcambra created an issue. See original summary.

levmyshkin’s picture

Hi pcambra, sounds good to me, I will have a look this and move calculation of caption in separate class/service. This GLightbox module was forked from Colorbox module, which is rewritten from D7 module. So it's old fashion legacy.

  • levmyshkin committed bbd4eea0 on 1.0.x
    Issue #3492657 by pcambra: Create a service for caption calculation
    
levmyshkin’s picture

Hi pcambra, I moved calculation for caption in separate service:

$formatter_service = \Drupal::service('glightbox.formatter');
$caption = $formatter_service->getCaption($variables);

I thought about alter hooks first, but caption will be rewritten anyway if alter will be before calculation. And for alter hook after calculation, it will get already replaced tokens. Maybe two alter hooks before and after calculation could help, but I don't know about all the cases for captions. I found that devs still use Image field without Media and maybe different another problems will buble up later.

levmyshkin’s picture

Status: Active » Fixed
levmyshkin’s picture

Status: Fixed » Closed (fixed)