- 🇨🇦Canada peterhebert
I am trying to use a field attached to the media entity 'field_caption' as the caption source, but when I chhose the Photoswipe Responsive field formatter on my node, the media field doesn't appear as a source, and I cannot figure out the correct token. I have tried:
[node:field_media:entity:field_caption] - repeats the caption from the first image delta on all images... no token for non-specific delta?
[media:field_caption] - nothingIs this possible? If so, can you document how to do this via a token, or using a hook?
- 🇨🇭Switzerland handkerchief
@peterhebert I had the same issue, I was able to solve this with the peprocess hook:
function HOOK_preprocess_photoswipe_image_formatter(&$variables) { // Get correct caption for the image. $imageDTO = ImageDTO::createFromVariables($variables); $media = $imageDTO->getItem()->getParent()->getEntity(); $media_title = $media->label(); $example_text = $media->field_example_text->value; $final_caption = $media_title . '<br>' . $example_text; $variables['attributes']['data-overlay-title'] = $final_caption; }
The code is just an example. Hope this helps someone.