I'm not 100% sure if this is a problem or not, but seems to be triggering issues in other modules that also use the taxonomy terms on node updates/inserts.

I have a Photo node type that I'm using with fupload (one image per node) and uses a taxonomy term to sort into photo galleries. After upload I click the "next" button and it takes me to the page where I can enter a title, description, and select the appropriate term. After I submit this page it updates the node with these values, however, the $node->taxonomy array doesn't appear to be formatted properly.

In the update operation in nodeapi the taxonomy array looks as follows (after running through fupload):

array(0 => array(4 => '4'));

Where 4 is the tid.

However, when I run an update on an existing node that doesn't use fupload the taxonomy array looks like:

array(3 => array(4 => '4'));

Where 3 is the vocabulary ID and 4 is the tid.

So it seem that code in the fupload module is causing the vid to be reset to 0.

I think where this is happening is in images.previewlist.imagefield.inc (around line 279):

      if (isset($form_state['values']['taxonomy_' .$fid])) {
        $node->taxonomy = isset($form_state['values']['taxonomy_' .$fid]) ? array_merge($form_state['values']['taxonomy_' .$fid], $node->taxonomy) : $node->taxonomy;
      }

It runs an array merge that seems to be causing it to fail. In my case $node->taxonomy is empty so this is:
array_merge(array(3 => array(4 => '4')), array());

The isset() call seems redundant here, so maybe this code could be rewritten as:

      if (isset($form_state['values']['taxonomy_' .$fid])) {
        $node->taxonomy = !empty($node->taxonomy) ? array_merge($form_state['values']['taxonomy_' .$fid], $node->taxonomy) : $form_state['values']['taxonomy_' .$fid];
      }

I've changed this on my own copy and it appears to be working nicely now.

CommentFileSizeAuthor
#1 taxonomy_imagefield_save_535148.patch1.19 KBhadsie
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

hadsie’s picture

Title: Problem setting taxonomy terms when using imagefield » taxonomy terms not set properly when using imagefield
Status: Active » Needs review
FileSize
1.19 KB

here's a patch for this issue.

grandcat’s picture

Also thank you for this patch. Will check this.

grandcat’s picture

Status: Needs review » Fixed

Comitted to HEAD. Thanks in advanced.

Status: Fixed » Closed (fixed)

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