working-taxonomy

mikegoodwin - May 19, 2008 - 17:37
Project:Imagefield Import
Version:5.x-1.0-beta
Component:Code
Category:task
Priority:normal
Assigned:Unassigned
Status:closed
Description

I messed around with this module a little bit. I've attached a patch that got the taxonomy portion working for me. The problem with the current implementation of the taxonomy code is that we use the taxonomy_form_alter function with an incorrect form id of 'image_node_form'. This will only work if your node type is named "image" (as with the Image module). However, if your node type name is different (e.g. 'photo' in the attached patch), then you need to use a form id of 'nodetype_node_form'. I simply changed the form id to 'photo_node_form' for my case, and it worked. Also, you have to uncomment the portion of the submit function that handles taxonomy, as is done in the patch.

Since I hard coded my node type's name into the form id, we still need to abstract this out to include arbitrarily set node type names. This shouldn't be too difficult to do. I just haven't had time yet.

AttachmentSize
imagefield_import.patch2.28 KB

#1

mikegoodwin - May 19, 2008 - 18:00
Title:updated patch» taxonomy code

I should mention that I'm not really certain how to create appropriate patches yet, and I wasn't totally clear with my first post. So here's the idea...There is code to include the taxonomy options on the upload page:

<?php
if ($files) {
    if (
module_exists('taxonomy')) {
     
// a little hack from the image_import.module to get the taxonmy controls onto our form---
     
$form['type'] = array('#type' => 'value', '#value' => 'image');
     
$form['#node'] = new stdClass();
     
$form['#node']->type = 'image';
     
//this form id must be changed to the appropriate node type_node_form
     
taxonomy_form_alter('image_node_form', $form);
      unset(
$form['type']);
      unset(
$form['#node']);
    }
?>

There are three references here that assume your node type is named "image". This may not be the case, and should be abstracted to find the correct node type name, whether it's "image", "photo", etc. I changed them for my case to be "photo" (my node type name) and everything worked properly. Additionally, I believe that the code in the imagefield_create_node_from function for taxonomy must be uncommented for the selected term to be appropriately applied:

<?php
if (module_exists('taxonomy')) {
    
$node->taxonomy = $taxonomy;
   }
?>

#2

mikegoodwin - May 20, 2008 - 00:45
Title:taxonomy code» working

I think that I now have the module fully functional for taxonomy, and it works with any node type name. Here's the portions of the imagefield_import_form() function that I changed. First, I get the node type name:

<?php
//get the content type and field names
 
$targetsetting = variable_get('imagefield_import_fieldname', FALSE);
  list(
$type, $field) = split(":::", $targetsetting);
?>

Then I fixed the taxonomy portion of the same function:

<?php
if (module_exists('taxonomy')) {
 
// a little hack from the image_import.module to get the taxonmy controls onto our form---
 
$form['type'] = array('#type' => 'value', '#value' => $type);
 
$form['#node'] = new stdClass();
 
$form['#node']->type = $type;
 
$form_id = $type . '_node_form';
 
taxonomy_form_alter($form_id, $form);
  unset(
$form['type']);
  unset(
$form['#node']);
}
?>

Then uncomment the taxonomy portion of the imagefield_create_node_from() function:

<?php
if (module_exists('taxonomy')) {
 
$node->taxonomy = $taxonomy;
}
?>

With these changes, my code is fully functional, as far as taxonomy is concerned.

#3

vordude - May 20, 2008 - 03:07
Title:working» working-taxonomy
Category:bug report» task
Status:active» needs review

I took your e-mail and rolled a patch with the file-- Will apply and test in the morning.

Other tests encouraged! :-)

AttachmentSize
imagefield_import_taxonomy.patch 3.11 KB

#4

vordude - May 20, 2008 - 19:20
Status:needs review» closed

Applied And tested. Thanks.

#5

vordude - July 28, 2008 - 22:14
Status:closed» fixed

Am I supposed to use Fixed, or closed?

Either way it's fixed.

#6

Anonymous (not verified) - August 11, 2008 - 22:22
Status:fixed» closed

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

 
 

Drupal is a registered trademark of Dries Buytaert.