Hello all!

I'm trying to make the Category module work with Image_Import, and, while I've made some progress, I have run into a seemingly simple issue which I hope one of you can help me with.

Basically, when the Preview button is clicked on the Create Image_Import screen, a dummy node is created and the node->taxonomy field set so that the taxonomy form values "stick" when the form is returned to the browser. I am trying to replicate this functionality with node->category, but have not had success thus far.

My problem: how to set node->category? I am really close, but can't figure out what I'm doing wrong.

Some background: the main reason I need node->category set is b/c I hacked the Image module to create subdirectories in the image path based on the category of the image. (See: http://drupal.org/node/70137). This is working well with Image and Img_Assist, but not with Image_Import, because node->category is not yet set when the files are imported and saved to disk. That is what I am trying to do!

The line I am trying to replace:
$dummy_node->taxonomy = $_POST['edit']['taxonomy'];

What I have so far:

  //this returns the array of selected cid values
  $terms =& _image_import_extract_cids($_POST['edit']['category']);

  //109 is the nid of my container, hardcoded here until I figure this out
  foreach ($terms as $term){
    $categories['109'][$term] = category_get_category($term);  
  }

  $dummy_node->category = $categories['109']; 

Can anyone help me with the proper way of setting node->category from the form elements? I've now spent 6+ hours trying different things, and I'm tearing my hair out! I'd be happy to contribute a patch back to the community if I can get this thing working!

Thanks!

Jon

Comments

jdw23’s picture

Well, I finally figured out how to save node->category from the form element....It certainly isn't difficult:

  $terms = _image_import_extract_tids($_POST['edit']['category']);
  
  foreach($terms as $term){
    $node->category = array($term=>array('cid'=>$term)); 
  }

I am still having some other issues, but I have been able to get Image_Import to work with Category instead of core Taxonomy.

bdragon’s picture

Status: Active » Closed (fixed)