i have a content_taxonomy field. Save options:Both.

the value has been lost after this: node_save(node_load($nid));

before:

[field_taxofield] => Array
        (
            [0] => Array
                (
                    [9] => stdClass Object
                        (
                            [tid] => 9
                            [vid] => 7
                            [name] => NAME
                            [description] => 
                            [weight] => 0
                        )

                )

after:

[field_taxofield] => Array
        (
            [0] => Array
                (
                    [] => 
                )

        )
CommentFileSizeAuthor
#5 ct_options_process.patch1.24 KBmh86

Comments

mh86’s picture

Category: bug » support
Status: Active » Fixed

you have to execute node_submit before node_save because in node_submit the terms get added to the field array

Gábor Mayer’s picture

don't work for me

$node = node_load(arg(1));
$content = print_r($node, TRUE);
node_save(node_submit($node));

Gábor Mayer’s picture

Category: support » bug

_Checkboxes/Radios_ !!!

Gábor Mayer’s picture

Status: Fixed » Active
mh86’s picture

StatusFileSize
new1.24 KB

seems there is a problem when trying to save the nodes manually.
the problem only occurs when saving the field in the cck way (or both).
I took a quick look into to code an tried to fix it. I attached the patch. Try it out, but I'm not absolutely sure if this can have any other sideeffects.

dafeder’s picture

I was having the exact same problem. Neither node_submit nor this patch seemed to make a difference. For now, just switching to tag saving works for me.

socialnicheguru’s picture

Title: node_save problem » Content Taxonomy is not saved when "cck" or "both" are specified

I am having the same issue. It is very frustrating. I am going to test out this patch.

Chris

miweb’s picture

Same problem for me (saving both, freetagging).

Trying to add a content in my content-taxononmy-fields (three different textfields for three different vocabluarys): only the content of the first field is added to my vocabluary an printed out in the node. The second and third field seems not to work. However this occurs after around 15 or 20 nodes. Everything works fine before.
And it works when the tag has already been added in the vocabulary! Unfortunately there a many new terms to add publishing new nodes.

And all my added tags disappear (at least they are not shown in the node) after changing some fields or workflows for this content type.

Is there somebody who knows why this error occurs and how to fix this? Step by step for a noob like me, please?

noomz’s picture

I have this issue too. And this patch is not work.

noomz’s picture

I found that structure of content_taxonomy from node_load is differ when you insert it back.

If you want to insert this

[field_issues] => Array
        (
            [0] => Array
                (
                    [14] => stdClass Object
                        (
                            [tid] => 14
                            [vid] => 3
                            [name] => Family
                            [description] => 
                            [weight] => 0
                        )

                )

        )

just use this

[field_issues] => Array
        (
            [14] => Array
                (
                    [value] => 14
                )

        )
phdhiren’s picture

I'm having similar problem, patch in #5 not works for me. :(

plan9’s picture

Subscribing

sepla’s picture

Subscribing.

Clément’s picture

Nobody has a working patch for this problem? Thank you.

xjm’s picture

Unfortunately Drupal 5 is not supported anymore, so this will probably not get fixed unless someone who is using the module in D5 themselves comes up with a fix and shares it.

xjm’s picture

Clément’s picture

Thank you for your responses. I'm using Drupal 6, but apparently the problem is still relevant. I'll look into the links if I find the solution. Again thank you.

Balbo’s picture

Using Drupal 6 and having the same problem.

I also use Hierarchical Select.

xjm’s picture

Re: #17/#18 (and maybe #12/#13 too) -- I'm not sure how it could be the same problem in 6.x? The setting options described in the title don't exist anymore. I'd suggest opening a new issue with a full description of your problem in that case. Be sure to indicate in the new issue how your vocab is configured, how your field is configured, which widget you're using, and whether you're editing the node normally with the node edit form or by some other means.

magnus’s picture

Status: Active » Closed (won't fix)

Cleanup of old issues. According to maintainer: "active development is only done for the 6.x branch! 5.x is not supported any more".
Reopen issue if problem still exist in 6.x branch.

noamdanon’s picture

I have a patch to fix this one on Drupal5, if anyone is interested:

In content_taxonomy.module under content_taxonomy_field() function add the following new case to the code:

      // if cck field was set to be saved as 'both' (on cck table as well),
      // then if node was saved via code (node_save()) and not via the node/edit form, this info was lost.
      // For example, when using the workflow history tab.
      
      // The fix is:
      // this hook with 'update' is called just before content_field() on content.module, that does the actual saving to DB.
      // When coming from node edit form, since form is submitted, the syntax of $node_field is: 
      // array(tid => array('value' => tid));
      // But, if called from node_save, the syntax is :
      // array(0 => array(tid => term_object)).
      // So we convert from one format to the other...
      // --------------------------------------------------------------------------------------------------------------------
    case 'update': 
        if (!isset($field['save']) || $field['save'] != 'both')
            return;
             
        // Check if $node_field is in the wrong format
        // --------------------------------------------
        $is_rebuild_node_field = FALSE;
        foreach($node_field as $tid => $tid_value) {
            if(!$tid && count($tid_value)) {
                foreach($tid_value as $internal_tid => $term_data) {
                    if($internal_tid && is_object($term_data) && isset($term_data->tid)) {
                        $is_rebuild_node_field = TRUE;
                        break;   
                        
                    }
                }
                
            }
        }

        // In wrong format - convert it to the right format
        // -----------------------------------------------------
        if($is_rebuild_node_field) {
          $node_field = array();
          foreach($node->taxonomy as $tid => $term) {
               if($term->vid == $field['vid']) {
                   $node_field[$term->tid] = array('value' => $term->tid);
               }
          }
          $node->{$field['field_name']} = $node_field;
        }




I tested it and it solves the problem completely.
See the comment inside the code to understand what it works and what it does.