Create a service for caption calculation

Created on 9 December 2024, 5 months ago

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 📌 Allow caption to use title and description for remote video Active had to duplicate this code.

📌 Task
Status

Active

Version

1.0

Component

Code

Created by

🇪🇸Spain pcambra Asturies

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

Comments & Activities

  • Issue created by @pcambra
  • 🇷🇸Serbia levmyshkin Novi Sad, Serbia

    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
      
  • 🇷🇸Serbia levmyshkin Novi Sad, Serbia

    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.

  • 🇷🇸Serbia levmyshkin Novi Sad, Serbia
  • 🇷🇸Serbia levmyshkin Novi Sad, Serbia
Production build 0.71.5 2024