Problem/Motivation

Having lean media for reusability is a common practice I've been seeing lately, you create a Media bundle with the minimum so it can be reused and then the configurable bit lives on paragraphs (or other), but mainly paragraphs.

This module has already clever implementations for parent paragraphs on the gallery side, but it would be nice to have paragraph token replacement too.

Proposed resolution

Add paragraph as a token entity on the formatter form, then load it if exists when the replace happens.

Issue fork glightbox-3487478

Command icon 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:

Comments

pcambra created an issue. See original summary.

pcambra’s picture

Working on a patch

pcambra’s picture

If this is an acceptable solution, I'll add an equivalent MR to https://www.drupal.org/project/glightbox_media_video

pcambra’s picture

Status: Active » Needs review
pcambra’s picture

  • pcambra committed 9c2df031 on 1.0.x
    Issue #3487478: Allow caption tokens from parent (paragraph entity)
    
levmyshkin’s picture

Hi pcambra, it will be tricky to define 'mainly' paragraph automatically. Glightbox image formatter which is being applied to Image field can be referenced to Media entity first and Media field attached in Paragraph directly or in nested paragraph with Gallery and Gallery Item paragraph types. Image field can be included in 'mainly' Gallery paragraph type directly. Paragraph module is not limited by any structure or nested levels.
It's possible to prepare tokens for specific (common, most popular) cases:
1. Multiple image field inside 'mainly' Paragraph (without Media).
2. Single image field in paragraph Gallery Item and Gallery 'mainly' parent paragraph type (without Media).
3. Multiple media field inside 'mainly' Paragraph.
4. Single media field in paragraph Gallery Item and Gallery 'mainly' parent paragraph type.

It can be one token 'Parent title', but here is another problem, which field must be selected for this token. Gallery id is being generated automatically without additional complexity with Text field at the end.

It can be token by reference:
referenece_field_name:parent_entity:reference_field_name:parent_entity:text_field_name

From first glance, it should be straightforward, but I'm afraid that Drupal doesn't support parent entity, because of circullar tokens (I suppose so, parent entities support children fields tokens, children fields tokens support parent fields tokens) and it must be tricky too:
https://www.drupal.org/project/paragraphs/issues/3067265

Here is a custom solution to create own site specific token:
https://drupal.stackexchange.com/questions/254406/how-to-get-token-of-pa...

I can create only 4 tokens for cases above, then it will be possible to select field for token, but site editor must be aware which token relates for his own site depends on its structure.

levmyshkin’s picture

I merged your request in 1.0.x-dev. I will try to add tokens on the next week.

levmyshkin’s picture

Status: Needs review » Fixed
levmyshkin’s picture

Status: Fixed » Closed (fixed)
zany’s picture

I have e.g. a "gallery" paragraph with "field_gallery_items" and "field_label", and a (nested) "gallery_items" paragraph with "field_image" and "field_description".

I want to use the "field_description" (which is alongside the "field_image") as custom caption description.

I notice the following: I can use "[paragraph:id]" (shows the same value on all glightbox images) and "[paragraph:field_label:value]" for custom caption and custom caption description (from the parent paragraph).
But I can not use "[paragraph:field_description:value]" (from the direct paragraph containing this "field_image").

Is the paragraph token supposed to be the direct paragraph entity containing the glightbox formatted field? Or is this intentionally the parent paragraph?

zany’s picture

On closer inspection I see the issue with my use-case: glightbox.theme.inc properly sets
$data = [$entity_type => $entity, 'file' => $item]; in line 303 -- which in my case sets a "paragraph" entity.
But line 307 overrides this with $data['paragraph'] = $parent; -- should this maybe set parent or such instead of paragraph (which hides the current entity)?

levmyshkin’s picture

Hi pcambra, I updated tokens for GLightbox paragraphs, please, use [paragraph_container:field_name] token for your Image/Media field:
https://www.drupal.org/project/glightbox/issues/3511270#comment-16018183