item.caption.link missing for videos in media field

Created on 31 July 2024, 4 months ago
Updated 15 September 2024, 2 months ago

I have a slider block created with a view in Slick Carousel format with fields body, link and media. Media field contains either an image or a video which is rendered on the background (slide_media), the body on top (slide_description) and the link is rendered around the media tag with a twig template. Everything works fine when media is an image, but the link is not rendered in the twig template as item.caption.link when media is a video. Drupal version is 10.3.1.

Twig customization:

{% set slide %}
  {% block slick_slide %}
  {% if item.caption.link %}
	<a href="{{ item.caption.link }}">
  {% endif %}
	{% if settings.split and not settings.unslick %}
      <div class="slide__media">{{ item.slide }}</div>
    {% else %}
      {{ item.slide }}
    {% endif %}
  {% if item.caption.link %}
	</a>
  {% endif %}
{% endblock %}
{% endset %}
💬 Support request
Status

Fixed

Version

3.0

Component

Documentation

Created by

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

Comments & Activities

  • Issue created by @kaipipek
  • Status changed to Postponed: needs info 4 months ago
  • 🇮🇩Indonesia gausarts

    Thank you.

    > Twig customization
    Does it work if using default/shipped template, and removing your customization?

  • I tested with Olivero theme and same behaviour: video is tiny and images are full width.

  • 🇮🇩Indonesia gausarts

    Not about how come, not clear here :)

    There is an option named Image linked by Link field under Media switcher option. Be sure to choose the dedicated Link field under Link option.

    This will wrap your media image with this link.
    Then you want exclude video, you can unwrap this link using the provided hook_alter almost like you did. But easier.

  • I tried Image linked by Link setting and the slide is wrapped with a link but it is not the right link which is one the fields of slide content. What am I doing wrong?

  • 🇮🇩Indonesia gausarts

    A good sign.

    See #5, updated with new info.

    Do not use emails, sometimes I updated my comments with extra useful info.

  • The links that are rendered around the slides point to the slide content node and not to URL in the link field of the node. However, the link field is correctly rendered as plain text if I add it into the fields of the view as Content:Link. It does not seem to matter if I select the link field under Fields or Caption fields in Style settings.

  • 🇮🇩Indonesia gausarts

    Check your selected View mode option. Verify that this view mode has the link field visible, in case hidden.

    Be sure to reuse the exact same link field and image field for the entire media types to work as mixed media contents.

    Remember this link and image fields are existing in the Media type Manage display, not Content type/ node one.

    Please paste your formatter form to better see the culprit.

  • 🇮🇩Indonesia gausarts

    You are confused between the link in node vs in media.

    You want to create a new or reuse existing link field in Media types > Manage fields/display.

    Because you are dealing directly with Content:Media an sich.

    Thus the fields must exist in Media, not Content or Node. Once they exist in Media entity, you can select them as options in this Media formatter.

  • I understand now that the issue is that my link field exists in Content/Node, because they are slide specific e.g. Product 1, Category B etc. and not media specific because same media is reused around the site. I suppose I need to use my hook for wrapping slides with content links as previously and figure out the namespace issue in case of video media.

    Here are my style settings:

  • Status changed to Fixed 2 months ago
  • 🇮🇩Indonesia gausarts

    The previous answers to focus on and separate Media field formatter which handles the link from Slick Views should fix OP.

    However should you want to use the hook_alter, that will do, too, but not as robust as Link inside a Media formatter.

    For reasons:
    Link in Node will only have one link applied to all Media items, while Link in Media will be unique to each Media item.

    However up to your design requirements, if that serves your purpose.

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

Production build 0.71.5 2024