Download & Extend

Sync between the editor and the upload field

Project:Drag'n'Drop Uploads
Version:6.x-1.x-dev
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:active

Issue Summary

The obvious :

If you suppress a file from the upload field it is not removed from the editor
If you suppress a link from the WYSIWYG editor that refers to a DnDU managed resource it is not removed from the DnDU upload field

I fully understand the why and that there is probably no "event" fired by WYSIWYG in such case but it would be worth seeing what can be done with the WYSIWYG module maintainers, because it render the "hide upload field" moot since can't manage the assets if you can't see them.
But allowing this allow the user to remove an asset he still has linked in the editor, AND put back most of the complexity of resource insertion in the WYSIWYG editor.

Comments

#1

Category:task» feature request
Priority:critical» normal

While I understand the what you're asking for and why, but the there really is no way to alert that you have removed the link from the WYSIWYG without a constant check for the text which is overkill and also removing the link from the WYSIWYG doesn't necessarily mean you don't want the file uploaded.

The other way around definitely has merit as if you delete the file the link will be broken, I will consider this for a up coming release.

Will keep you informed on the progress.

Cheers,
Deciphered.

#2

thanks for your answer(s).

It may be only an option or even a separate module because I understand it has merits in only a certain kind of use case, but an important one : a complete "composite document" building tool.

Maybe that sync should only be done at submit time and I thought about using the phpquery library.

As my post say maybe there is something to be done with the WYSIWYG guys to enrich the kind of information they expose, maybe via a hook.

I have a feeling there is "the" killer app for editors and maybe Drupal sleeping there :)

Thanks a lot for your time and support.

#3

Hello and thank you for this nifty module which, along with Image Resize Filter, makes for a very user-friendly image manipulation UI.

At any rate, I agree with Annakan that there ought to be a way for uploaded images to be removed from the node, if the link to them is removed from the body. I don't think this has to be done at the moment the link is removed, especially considering the dependency on WYSIWYG firing an event. I suspect that upon preview/submit should be fine for most use cases requiring this.

That said, perhaps one way to accomplish this would be implementing hook_nodeapi with $op = 'validate', then dropping the imagefield element(s) from the node form if a reference to the image's filename or filepath isn't found in the node body. I'm fairly new to Drupal development, so I may be off in left field, but this seems feasible. I'll take a crack at it, and report back if I have any success.

Regards, C

#4

OK, here's a first pass. It appears to work properly in the most basic use case: Add node >> drag'n'drop image >> save node >> edit node >> cut image from WYSIWYG >> save node.

<?php
   
// FYI: added to dragndrop_uploads.module
function dragndrop_uploads_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
  switch (
$op) {
    case
'validate':
     
// For now, assume we only want to do this if we're hiding the widget
     
if (variable_get('dragndrop_uploads_hide_' . $node->type, 0) > 0) {
       
$haystack = $node->body;
       
$attached_images = $node->field_image;
        foreach (
$attached_images as $key => $attached_image) {
         
$needle = $attached_image['filepath'];     
          if (
$needle <> '' && strpos($haystack, $needle) == FALSE) {
            unset(
$node->field_image[$key]);
           
// delete the file too?
           
node_save($node);
          }
        }
      }
    break;
  }
}
?>

KNOWN BUGS:
Previewing the node after cutting an image seems to break it: neither removing the deleted imagefield, nor allowing saving the node afterward with a message of "This content has been modified by another user, changes cannot be saved". I believe this is mainly due to calling node_save() from within hook_nodeapi(). Perhaps switching to "$op = 'submit'" would help, but it seems to me that we would want this to work for previewing.

Additionally, cutting an image before having saved the node the first time (i.e., during node add) also seems to break it. The file is deleted from the server, but the imagefield reference to it appears to remain. I suspect that modifying the form (i.e., $a3) might be necessary, which leads me to believe that '$op = validate' is the right place to do this.

So, obviously more work is needed, but not tonight.

Regards, C

nobody click here