I have searched around and can't seem to find an answer for this one. Seems pretty simple to me.

I have nodes that have images attached to them and when you click on the image in the node, it takes you to the actual image node. I want to disable this. Any clues?

Thanks in advance.

Comments

WorldFallz’s picture

How are the links being created? Normally, you just leave off the HREF attribute.

lanexa’s picture

Thanks for the response. The node.tpl.php file only shows the call to the 'content' - no ability to edit, so I can't remove the HREF.

If I knew which file to edit, it would be a simple fix. I've looked through image.module, node.module with no luck. I was able to remove the LINKS to Original and Thumbnail by editing the image.module.

Any other ideas? Thanks.

WorldFallz’s picture

but the link in the content node is being created by whatever means you create that node... are you using tinymce? fckedit? image attach? etc.... How do you edit the content nodes and insert the images into them?

lanexa’s picture

I am using Image_attach.

I have a new content type that I created that allows me to upload a new image or use an existing image to attach. The content is created using this new content type. I found the image_attach.module in modules/image/contrib, but I'm not sure this is where the HREF is.

Does that make sense? Thanks again for the help...this is tripping me up.

kenkrum’s picture

I am having the exact same issue. When I attach an image (using image_attach) to a story lets say, it automatically creates the image as an href to itself. This does not make sense in that case and I would like to turn off that link all together.

lanexa’s picture

I think it is a simple fix....just a matter of finding *where* that HREF is called from. I'm still looking.

Line 386 in my image_attach.module starts these lines:

    $output = '<div style="width: '. $info['width'] .'px" class="image-attach-body">';
    $output .= l(image_display($image, $img_size), "node/$node->iid", array(), NULL, NULL, FALSE, TRUE);
    $output .= '</div>'."\n";

If I comment out the first one, no image shows up. I do not see the HREF here.

Yet, when I view source, here is the relevant code snip:

<div class="content"><div style="width: 400px" class="image-attach-body"><a href="/node/33"><img src="http://www.blah.blah.blah.com" alt="The Penthouse" title="The Penthouse"  class="image image-preview " width="400" height="237" /></a></div>
<p>The Penthouse is a fully furnished, luxury unit.</p>

the "href" is in there. hmmm....maybe I need to look for the class "image image-preview" within the module.

WorldFallz’s picture

Yeah, I've been playing around with this too. There's several places the code appears. I've been working with the one in the theme_image_attach_body function (the very end of the image attach module). There's no HREF because the l(...) function is the theme function that actually creates the hyperlink (which is why you don't see the HREF in the module itself.

Simply removing that function leaves:

image_display($image, $img_size) which doesn't show the picture. That's where I stopped. I think what you need to do is change that into a simple IMG tag which would change that line to:

$output .= '<img src="'. image_display($image, $img_size). '" />';

I just haven't had a chance to try it yet to verify.

Also, hacking a module constantly gets to be very old--- you may want to file a feature request with in the module's issue queue to have the hyperlink optional.

Post back if it works.....

lanexa’s picture

WorldFallz, looks like we both landed in the same place. :-) Thanks for the input.

I agree re: hacking modules, and I will request that as a feature. Thanks a lot for the input.

lanexa’s picture

Finally found it.

file: image_attach.module

Look for this line:

/**
 * Theme the body
 */
...
$output .= l(image_display($image, $img_size), "node/$node->nid", array(), NULL, NULL, FALSE, TRUE);

and change it to this:

    $output .= image_display($image, $img_size);

I admit, I do not know the implications of this, as this is purely a development site I'm testing it on - not in production yet. I will continue to test it for my specific need, but I wanted to share how I fixed it since so many have helped me here in the past. Thanks.

kenkrum’s picture

I ended up using the img_assist module with the Image module and I am finding it much better and easier than img_attach. Here you can easily edit that link setting as you add the image.

WorldFallz’s picture

Thanks for the update... good to know.

tsolan’s picture

In Drupal 6:

If you don't want to hack the module directly (and most probably lose your changes when you update it), you can also override the theme_image_attach_body function by having the same function in your theme's template.php and replace 'theme' in the function name with your theme's name. For example, for a theme called 'drop' you would add the following to your template.php to completely remove the image links:

function drop_image_attach_body($node) {
  $img_size = variable_get('image_attach_size_body_'. $node->type, IMAGE_THUMBNAIL);

  if ($img_size != IMAGE_ATTACH_HIDDEN) {
    drupal_add_css(drupal_get_path('module', 'image_attach') .'/image_attach.css');

    $image = node_load($node->iid);
    if (!node_access('view', $image)) {
      // If the image is restricted, don't show it as an attachment.
      return NULL;
    }
    $info = image_get_info(file_create_path($image->images[$img_size]));

    $output = '<div style="width: '. $info['width'] .'px" class="image-attach-body">';
    $output .= image_display($image, $img_size);
    $output .= '</div>'."\n";

    return $output;
  }
}
d.sibaud’s picture

for working the correct way is to replace:

function theme_image_attach_body($node) {

with

function phptemplate_image_attach_body($node) {

-------
Everytime you hack the core somebody die.
Please don't do it.

http://www.tourtools.it
http://www.realizzazione-siti-web-drupal.it

theropodx’s picture

This works great--thanks. BUT NOTE: you must leave the links set to "same window" under the image/image-attach module settings. If you set the links to hidden, they still appear, and this script doesn't work. So odd...

kierduros’s picture

Just a small change, but without it, the images just vanish off pages.

function drop_image_attach_body($node, $iid) {
  $img_size = variable_get('image_attach_size_body_'. $node->type, IMAGE_THUMBNAIL);

  if ($img_size != IMAGE_ATTACH_HIDDEN) {
    drupal_add_css(drupal_get_path('module', 'image_attach') .'/image_attach.css');

    $image = node_load($iid);
    if (!node_access('view', $image)) {
      // If the image is restricted, don't show it as an attachment.
      return NULL;
    }
    $class = 'image-attach-body' . ($image->status ? '' : ' image-unpublished');
    $info = image_get_info(file_create_path($image->images[$img_size]));

    $output = '<div style="width: ' . $info['width'] . 'px" class="' . $class . '">';
    $output .= image_display($image, $img_size);
    $output .= '</div>'."\n";

    return $output;
  }
}
crispinbailey’s picture

I recently noticed after updating to Image 6.x-1.0Beta6 (and therefore the latest version of Image_attach) that this override no longer overrides.

adoo’s picture

Thanks a lot men, you've just ended 1 hour of changing the module code. Thanks again.

bcobin’s picture

Many thanks to tsolan et.al. - you guys (and girls) are the BEST!

A most excellent "save" for a difficult problem. The Drupal community ROCKS!

oceanscience’s picture

The templete.php override mentioned in this comment worked really well on my site. so thx

However i have just realised it's not working anymore, and wondered if an update to the image attach module stopped this override from working.

Any ideas?

Thx

oceanscience’s picture

Just checking the changelog for the image / image_attach module and there are changes to the themeing functions

#412288 by joachim: Changed structure of theming functions for attached images.

maybe this has something to do with the problems

Of course it could just be something else.

adixon’s picture

Yes, exactly. You can do a solution similar to the above one by defining your own theme, but an easier, global fix is to comment out line 657 in the image_attach.module file, i.e.

// $link_destination = $options['link'];

that means none of your attached images will be linked to anything, which is what I usually want (or if I want them to link to something, I do that using a different tool).

MikeNGarrett’s picture

Here's a way to get just the image source using regex on the theme side:

$image = $node->content["image_attach"]["#value"]; 
preg_match('/(?<=src=")[^"]*/', $image, $img_url);
print('<img src="'.$img_url[0].'"/>');

This will print the image url instead of all that other slop.

Use this code in a node template, eg. node.tpl.php

I hope this helps.