Hello! I've made it so that thumbnails are shown on node teasers. Is it possible to make the thumbnail link to the node? If not, that would be a great feature for this module.

Solutions and Work-arounds

I have not tested, but here is a summary of suggestions from the comments below.

  • @azink wrote the File Entity Link module after finding no solution here. See #20 below. By design, it works with File fields, not the deprecated Multimedia asset field type. Several comments report that the module works well (#27, #36, #40).
  • If you are using Views with a Fields display (not Nodes) then select the "Strip HTML" option and enter <img>, then use the "Output this field as a link" option. See #29, #31.
  • Edit the node.tpl.php file in your theme directory. See #10.

In #2 and #17, the maintainers suggested they might accept a patch. In #28, one of the maintainers closed the issues, considering the File Entity Link module a solution to the issue.

CommentFileSizeAuthor
#34 media-link.patch1.35 KBJody Lynn
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Mèche’s picture

Subscribe

effulgentsia’s picture

Component: Documentation » Code
Category: support » feature

Not currently possible with Media module alone, but could be done with a smallish custom module that either defines its own formatter for the media field type, or extends the 'media' formatter.

If someone wants to submit a patch on this issue that adds a 'Link media to' setting to the 'media' formatter, similar to how core's Image module does for the 'image' formatter, it would be great, and I'm definitely open to committing something like that. However, note that this is more challenging for media, since the corresponding file entity being rendered might not be an image, and might also display fields, and there's issues with adding anchor tags around block-level HTML.

Toxid’s picture

I solved this in the theme node.tpl file by running the image through the l() function to generate a link to the node.

csunny’s picture

Subscribe

Niklas Fiekas’s picture

Subscribe.

aaron’s picture

i currently also get around the issue by using the 'rewrite field' option when adding it in views.

an issue would be context though -- for instance, when used in wysiwyg.

Shadlington’s picture

Subbing.

CrashNet’s picture

Could you provide more detail on your solution Toxid?

parasolx’s picture

just wanna to ask, how did you put your thumbnails? through media browser or field?

Toxid’s picture

I used bartik template for this, and edited node.tpl.

hide($content['whatever fields you want to display under the image']);

// If the node has an image field, we need to hide it, or else it'll echo with the render($content) as well.
if (isset($content['field_image'])) {
  hide($content['field_image']);
}

// Render everything that wasn't hidden before
echo render($content);

// And here we generate the link, I only wanted them on the thumbnails on the teasers
if (!$teaser) {
  // If not a teaser, render the image
  if (isset($content['field_image'])) {
    echo render($content['field_image']);
  }
}
elseif (isset($content['field_image'])) {
  // Since it is a teaster, render the link
  echo l(render($content['field_image']), 'node/' . $content['body']['#object']->nid, array('html' => TRUE));
}

echo render($content['whatever fields you want to display under the image']);

In my example, field_image is the name of my field. I also have youtube thumbnails, so if you want that you simply duplicate the if statemens and replace field_image with the youtube field name.
My method makes the image display last, since render($content) contains the rest of the information. Use the hide function to hide the fields you want below the image, and render them after the image link. If you need to see the fields in $content, just use print_r($content).

Niklas Fiekas’s picture

Thank you.

Just a tip: You don't have do check variables using isset when passing them to render and hide.

Toxid’s picture

Thanks, that's good to know. Drupal usually gives me a message saying "variable index not defined" when I don't use isset. But perhaps that's only a setting that needs to be changed.

Niklas Fiekas’s picture

This is off topic here, but render and hide are special, because they take references:

function render(&$element) { ... }

minneapolisdan’s picture

subscribing

energee’s picture

subscribing, #10 did not work

Toxid’s picture

@ energee, You must replace parts of the fields in code to correspond your nodetypes fields. If you just copy and paste then it won't work.

JacobSingh’s picture

Version: 7.x-1.x-dev » 7.x-2.x-dev

This will not happen in 1.x and *may* be accepted to 2.x if someone writes a patch for it, but more likely it should live as separate contributed module.

energee’s picture

@Toxid, I was aware of that, however didn't see any success with this, ended up working around this with css and html to float an anchor over the video. I'm sure this will be corrected in the module soon.

liquidcms’s picture

i used a PHP views field with this as the output:

echo l(strip_tags($data->field_field_video[0]['rendered']['#markup'], '<span><img>'), "node/" . $row->nid, array('html' => true));

ugly, but worked... this should be a formatter within the media module.

azinck’s picture

I just created a really simple project called File Entity Link that meets my needs. As I mention on the project page:

  • This module has only been tested with the fields of type "file". I know it will not work with fields of type "multimedia asset". I haven't tested it with "image" fields.
  • Links are placed around only the file portion of the file entity. If you've added fields (like caption, etc) to your entity they will not be linked. This was preferable for my application and informed the architecture of this module.
  • Any type of file can be linked, you're not limited to just applying links to images. Of course, it's possible some file types will output markup that will not acquit itself well to being wrapped in a link

It's simple and I'm not sure I've chosen the best architecture for it but I really wanted to be able to link just the file (not other fields on the file entity) so this is what I went with. I hope it helps some folks.

idflood’s picture

I would add that another workaround is to use the display suite module (http://drupal.org/project/ds).

azinck’s picture

@idflood:

While I've used Display Suite I'm not an expert with it. How would you propose to solve this with DS? Would you add a custom field?

idflood’s picture

My bad, it was not the display suite module that was displaying that... it's the field_slideshow module. See possible options:
http://cl.ly/3N0a2a420n0L2O0S232a

bpeicher’s picture

The ability to link a thumbnail to a node would make this module much more useable. It seems strange that the rewrite output function in the Views module works on everything but a media field.

azinck’s picture

bpeicher: did you try File Entity Link or Field Slideshow? With a little configuration either of those two modules should be able to solve your problem.

dlsmore’s picture

The File Entity Link and Field Slideshow solutions seem to work with images, but does anyone have an idea of how to link video (youtube, vimeo) thumbnails to the node?

dlsmore’s picture

Ah, answered my own question. So I upgrade to the latest dev version of Media and File Entity, and had File Entity Link installed too. Then you have to use a field type of "file" instead of multimedia asset. File Entity Link then does the linking of the thumbnail.

Devin Carlson’s picture

Status: Active » Closed (fixed)

As per #20 and #25, the File Entity Link module can be used to accomplish the functionality outlined in the original issue. Confirmation was given that the module works in #27.

Musicious’s picture

Hi Guys, I solved this without the need for other modules...

In views, in the fields settings.

Select strip html, and then put "< i m g >" (without spaces) into the ignore tags field form.

Then select rewrite as URL, as you would normally.

Have a cup of tea.

Will.

cpelham’s picture

@Musicious What did you re-write the URL to be (to get it to link to the node that the img file field is attached to)?

Musicious’s picture

@cpelham I have forgotten.

Right went and checked...

Yeah just select 'Output this field as a link'

then put this in link path

node/[nid]

( I loaded nid as a field , above this field, then selected the do not display option for that field, making nid a token)

Hope that helped.

cpelham’s picture

Most of the media formatters seem to hardwire the output as a link to the media. so selecting "output this field as a link" just wrapped a second link tag around the hardwired one. But selecting the formatter "media" and a size like "medium" produced an image without a link tag wrapped around it. so then I could successfully do what you suggested. Thanks!

Musicious’s picture

I think I achieved that when Selected "strip html", and then put "< i m g >" (without spaces) into the ignore tags field form.

So that striped all the html apart from the image, then made the image the link I wanted.

Well glad you got it sorted.

Jody Lynn’s picture

Status: Closed (fixed) » Needs review
FileSize
1.35 KB

The file_entity_link module does not work for multimedia fields. It also seems strange to add an extra module just to get a link.

This patch adds the option for links in the media field.

Status: Needs review » Needs work

The last submitted patch, media-link.patch, failed testing.

altrugon’s picture

azink got the solution on #20 >> http://drupal.org/project/file_entity_link

Jody Lynn’s picture

Right, but like I said it doesn't work for multimedia fields. And it should be included as an option in media module, not as a separate module.

azinck’s picture

Jody Lynn: multimedia fields have been deprecated.

samwillc’s picture

The solution at #29 by Musicious is the way I am trying to do it. Adding another module just for this is insane, this is a totally standard thing linking a thumbnail to a full node page.

The problem is with Musicious's suggestion is that I get those pesky edit/delete contextual links (which link to the file) showing up in plain text once the div with class "element-invisible" has been stripped.

It was so easy when you just added a field of type 'image' (instead of 'file' using the media module), then views can automagically link to content.

Sam.

samwillc’s picture

bxCreative’s picture

#40 works perfectly!

dwkitchen’s picture

Status: Needs work » Reviewed & tested by the community

#40

Devin Carlson’s picture

Status: Reviewed & tested by the community » Fixed

The file entity link module is a great solution for linking images to their parent entity.

See #1392900: Integrate File Entity Link's features into File Entity? for discussion on incorporating the module into File entity.

Status: Fixed » Closed (fixed)

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

Anonymous’s picture

Issue summary: View changes

Added summary of proposed solutions.

stijndmd’s picture

Issue summary: View changes

#40 works like a charm.
But shouldn't this be in Media?

Why do we get the option to either link to "file" or "content" when both options link to the file here?
The option "link to content" in Media should by default do what the option given by #40 does, IMO.

Sagar Ramgade’s picture

+1 for this, I think this should be part of the Media module.

karlkablisk’s picture

So many years of discussion since this issue and is still a problem :/

I was struggling with this and after reading a lot of the multiple discussions I came up with this method for VIEWS using media with youtube.

1. Get this and install this module
http://drupal.org/project/file_entity_link

2. Go to file settings for your display
admin/structure/file-types/manage/video/file-display
and choose the one you want to use (like preview for example) and use the youtube thumbnail.
Check the box at the bottom so the link goes to the content and not the file.

3. Make your view as usual to use the youtube preview

4. Go to rewrite settings and choose STRIP HTML
Be sure to put a few exceptions I put these
< img > < div > < ul >
(Without the spaces! The < a > link default in this is what makes the link not work so you are using this feature to strip it out)

5. Your content should display on the page with the title above it. The link to the content should work, so now you just need to get rid of the text, but it doesn't have any styling. So I suggest CSS
.file-video-youtube {
font-size: 0px;
}

This gets rid of the text and the linked image should work. Not the best solution but it only requires 1 module. I think the module makes fields work by default so views is the hard one to get a workaround for.