Once you've attached an image to a node, there's no way to "detach" it (other than deleting the image node)

There might be a "remove" (delete ?) checkbox next to the image thumbnail in the "attached images" fieldset on the node's edition form.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

moshe weitzman’s picture

I noticed this too. Suggested solution sounds good to me.

Coyote’s picture

I hate to say "me too", but... yeah. This is sort of a pain. There needs to be a way to remove attached images easily from the node.

kwillett’s picture

FileSize
1.05 KB

Here's a patch which will allow detaching images.

moshe weitzman’s picture

Status: Active » Needs work

almost ... we don't access variables from $_POST directly. Also, is the idea to detach or to delete the whole associated node? I could go either way.

seanr’s picture

My suggestion would be to provide both options (delete and detach buttons for each image). I'd very much like to see this get committed in some fashion even if not exactly as submitted - it's a fairly big hole in the module's functionality right now.

seanbfuller’s picture

Is the better solution to reference $node->detach instead of $_POST['edit']['detach']?

Otherwise code seems to work so far.

One thing about the detaching vs deleting issue is that the current image_attach works on a one-to-one relationship. There is no way to upload an image and then use that uploaded image in several different nodes, meaning that simply detaching an image is the same as orphaning it.

I'd love to see some sort of file explorer API that allows content creators to browse image nodes that he or she has access to and choose one from the list to be the image for the post. Walkah did a great job taking the original nodeapi_image code and paving the way for something like that with image_attach. I’ve yet to do the research to find if anyone is working on something like this (eg- node relationship). If anyone knows of anything, give a shout.

yched’s picture

As a comment to Sean's last paragraph in comment #6 :
Some excellent work was put in the 4.7 rewrite of img_assist.module, even if it is currently "only" used to insert images in textareas. I sometimes think that the interface of this module should be used in other circumstances (image manager, image_attach, images field for CCK, etc...)

I don't want to hijack this thread, though :-)

dman’s picture

Funny, I built an 'attach' . module just yesterday for connecting nodes with existing files!
Bundle here (it requires a patched filebrowser) -
http://drupal.org/node/72451#comment-113562
Small enhancement does one job. Didn't think of 'detach' but it is needed as I found that with multiple 'owners' (now possible) a single delete is bad news.

Works on 'download' files rather than specifically images so far.

I was thinking of bundling it with a larger module, but am not really sure what the bigger module is...

.dan.

moshe weitzman’s picture

considering how this module is used, i think the expected outcome here is that the attached image is simply deleted. no need to create an orphan.

seanbfuller’s picture

yched, I've got to say that I finally got around to building an install with image, image_assist, and tinymce with the drupal image button and I'm really loving it. These three modules work great together and I'm using them in upcoming projects.

The other day I was thinking about the differences between image_assist and image_attach. One concept that seemed to hold true is that image_assist is for inline images that are embedded in the content, whereas image_attach is for structured images that exist at the "top" level, along side the title. Image_attach images should be used for places where the image is displayed in a structured and consistent manner.

I could see a situation where users could implement both kinds of image in one post, although I admit there would need to be some systems in place to make this distinction obvious. In regards to detaching images, I could see the image_attach module checking for the image_assist interface, and using that to add images. You could then "detach" the image, but still have the image in your "my images" list.

Image_attach would still be on a one-to-one relationship basis, but would have a slightly different function than the multiple inline images.

David Lesieur’s picture

BTW, this patch integrates the "detach" feature in a similar way to the Upload module.

smoothify’s picture

I submitted a simple patch (for the 5 version - but should work on others too) for the ability to remove attached images...

http://drupal.org/node/124259

drewish’s picture

i've marked http://drupal.org/node/124259 as a duplicate of this.

drewish’s picture

marked http://drupal.org/node/131275 as a duplicate

jeanhr’s picture

March 28 2007...

Ok Drewish for the duplicate - http://drupal.org/node/131275

But which patch do you recommended using?

Jean

sigsby’s picture

If you enable attaching existing images, there is a really easy fix for detaching images with image_attach & Drupal 5.1, Just move one line in image_attach.module. Change this on line 162:

if ($node->iid) {
  db_query("DELETE FROM {image_attach} WHERE nid=%d", $node->nid);
  db_query("INSERT INTO {image_attach} (nid, iid) VALUES (%d, %d)", $node->nid, $node->iid);
}

to this:

db_query("DELETE FROM {image_attach} WHERE nid=%d", $node->nid);
if ($node->iid) {
  db_query("INSERT INTO {image_attach} (nid, iid) VALUES (%d, %d)", $node->nid, $node->iid);
}

Then select the first item in the select box of existing images (should be empty, submits $node->iid = 0) and viola!

Sorry but I don't have time for a patch. Patching would really be better suited to a proper fix anyway.

seanr’s picture

Priority: Normal » Critical

Can we please fix this sooner rather than later? I've got an image attached and now can't get rid of it.

drewish’s picture

Priority: Critical » Normal

the simple way is to just delete the image...

smoothify’s picture

drewish; deleting the image isn't that great a solution - what if you want to keep the image attached to other nodes or keep the image on the site for other reasons. So i don't agree that its the simple way.

I provided a patch (unfortunately on a new duplicate issue - sorry for that), but you were aware of it and someone else has also posted similar code on here.

Its a very simple change - wouldn't it be easier for someone to review the minimal code changes and commit to cvs, than keep having to respond to requests for this important feature?

I've attached the same patch as before on here, i haven't tested to see if it works on the latest version though but the changes are really small.

drewish’s picture

Status: Needs work » Needs review
FileSize
1.5 KB

small change to you patch, added a t() and moved the array definition. if someone will test this out i'll commit it.

drewish’s picture

Status: Needs review » Fixed

radiantsouls, between finals i found a little time to test this and it looks good so i've committed it. thanks for the patch i'm sure you'll make quite a few friends with this.

Anonymous’s picture

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

I'm still having this issue with the inability to "unattach" images. In the meantime, I have deleted the files, but the link is still created, leaving a broken image icon displayed in its place.

I looked through the changelog for 6.1.beta5 (which I'm running), but don't see a note on any patch that was committed. Was it committed? Or, should I run the above patch--and, if so, is that going to jive with 6.1.b5, since this is an issue "fixed" 2.5 years before the latest release?

Any suggestions would be appreciated!

(I'm trying to avoid raiding my QSL dbases to kill node relations...)

marina_v’s picture

Status: Closed (fixed) » Needs work

subscribing under #23, please fix in later releases....

joachim’s picture

Status: Needs work » Closed (fixed)

Just select the 'None' option at the top of the attached images list.

dr_morel’s picture

Thanks for the reply joachim

Well, I feel a little silly. That worked. However, selecting "-None-" does generate an "Invalid or missing image file for upload and attach." error and both images that are currently attached remain attached until you select "Preview" or "Save".

I guess I believed the error message too readily...

Thanks!
JJ

joachim’s picture

> "Invalid or missing image file for upload and attach."

Did you press the 'attach' button? Don't. That's only if you have a file you actually want to attach.

tracerhand’s picture

Status: Closed (fixed) » Needs work

So:

To allow deletion/detachment of an image from a node, we must display a list of all previously uploaded images? And then the user must choose "None" at the top of that list, and save the node?

If so, this is a "fix" only for sites that have "Attach existing images" enabled in the Image Attach preferences. Which leaves me - and presumably many others - out in the cold. (I don't want users to have the ability to insert images uploaded by someone else. And they wouldn't want to - all they care about is their own image.)

joachim’s picture

Hmm, I thought we'd covered this case...

At any rate, could you file a fresh issue rather than reopen an ancient one? Though I say this with a caveat -- few developers are working on this module any more. I'll review a patch but I won't have time to work on one.