As in img_assist for drupal 4.7 the upload window should contain the same forms as the page "create image". The attached image shows the create-image-page on the left and the upload window on the right.

Comments

TobiasH’s picture

Unfortunately I cannot locate the bug. At the moment I must edit every image after uploading it to select the taxonomy terms. Perhaps someone who is more experienced could take a look at it. thx

zoo33’s picture

Component: User interface » Code

I suspect it has to do with this patch which removed some form logic. This probably needs some investigation. Maybe we have to revert some of those changes and work around the problems that we had some other way. I don't have time to work on it right now, but hopefully later. Until then, if someone wants to have a look, well, you're always welcome!

TobiasH’s picture

I think it has to do with the img_assist_node_add function arround the line 603.

   $output = drupal_get_form('image_node_form', $node);
   foreach (array('title', 'teaser', 'body') as $field) {
     if ($_GET['edit'][$field]) {
       $node[$field] = $_GET['edit'][$field];
     }
   }
   $output = drupal_get_form('img_assist_node_form', $node);
   drupal_set_title(t('Submit %name', array('%name' => node_get_types('name', $node))));
}

If I change the line before last to

   $output = drupal_get_form('image_node_form', $node);

then the form is complete, but the form submit redirects to frontpage again. I don't know if this can help anyone to fix this.

moonray’s picture

Looks to me like the callbacks aren't being done. All the missing parts are from hook_form_alter functions from other modules. I don't think the patch that you are referring to did this.

Definitely needs looking into.

moonray’s picture

OK, yep, just as I thought.
Because the form has a custom form_id (version 4.7 didn't have this problem, it's a 5.0 issue), when the modules check for $form['type']['#value'] . '_node_form' == $form_id, they no longer get image_node_form, but img_assist_node_form.
And so they don't execute the script...

moonray’s picture

Status: Active » Needs work
StatusFileSize
new859 bytes

OK, this patch works. But... it's not very pretty and might cause some damage (not sure), since it violates some rules.
It uses image_node_form($node) as the function name, rather than a function name preceded by img_assist (which is drupal's version of namespaces).

Maybe someone else can come up with a better solution?

moonray’s picture

Sorry, scrap that last patch (I should test more thoroughly before submitting!).

zoo33’s picture

Status: Needs work » Needs review
StatusFileSize
new6.72 KB

Phew. I just put a couple of hours' work into this, and I think it may have been worth it.

I managed to get rid of the node form functions and just rely on image.module's own form handling. The only thing that needs to be treated differently in img_assist is really the redirect after an image has been submitted. I defined a second submit callback to image_node_form which allowed me to override the redirect. (I knew that you could define multiple #validate callbacks, but with #submit it was just a wild guess.)

There is no apparent way (to me anyway) that the second #submit callback can catch the nid of the uploaded image. So I added a snippet to img_assist_nodeapi which saves the nid to a global variable as the node is inserted. There may be a better way to do this.

Anyway, if this works it is a lot more simple than the previous solution. (And I think it does work.) So, please try it out and check the code!

TobiasH’s picture

Thank you zoo33! It seems to be a good solution. I'll test it.

TobiasH’s picture

Status: Needs review » Reviewed & tested by the community

The patch in #8 is working for me. Once again, thank you!

zoo33’s picture

Status: Reviewed & tested by the community » Fixed

Committed.
Thanks for your help investigating this!

moonray’s picture

Status: Fixed » Needs work

Not an issue with the functionality of the code, just some spelling issues.

function img_assist_node_form_submit($form_id, $form_valuess) {
// Get the nid of the newly created image (catched by img_assist_nodeapi):

should be

function img_assist_node_form_submit($form_id, $form_values) {
// Get the nid of the newly created image (caught by img_assist_nodeapi):

and for this comment... (are you Swedish by any chance? :-) )

+ * - Catch nid:s of recently uploaded images
+ * - Catch nids of recently uploaded images

and one more

zoo33’s picture

Status: Needs work » Fixed

Thanks!
Not sure if that's a typical Swedish way of writing plural forms, but yes, I'm Swedish. :)

("Catched"? Hope my old English teacher isn't watching...)

moonray’s picture

Yes, it's very Swedish. I lived in Sweden for a year or two... :-)
Thanks for the fix.

zoo33’s picture

Status: Fixed » Needs review

Oh, I just remembered something. Look at this part:


-    // Allow the following fields to be initialized via $_GET (e.g. for use
-    // with a "blog it" bookmarklet):
-    foreach (array('title', 'teaser', 'body') as $field) {
-      if ($_GET['edit'][$field]) {
-        $node[$field] = $_GET['edit'][$field];
-      }
-    }

That functionality was removed by the patch. My intention was to maybe add that back in another function, but it slipped my mind.

Is anyone actually using that? I can't really imagine a use case for it since it's difficult for a user to change the $_GET variables in the case of img_assist's popup window. Maybe it's something that was copied over from node_add()? I checked the current version of that function, but I didn't find any $_GET tricks there...

I suggest we skip it.

moonray’s picture

I was wondering about the same bit of code a while back, but didn't know what module would use a "blog it" bookmarklet, so I just left it alone.

zoo33’s picture

Status: Needs review » Fixed

No one's gonna miss it. I'd be very surprised.

Anonymous’s picture

Status: Fixed » Closed (fixed)