Am working on a patch that would allow support for image_attach and bulk import of image nodes. I'm having trouble figuring out how to grab the particular value from a row. I've combed through the module a few times and just can't figure it out. What is the array that the key->value pairs are living? How do I address those?
I'd be so grateful for an answer on this.
Comments
Comment #1
Robrecht Jacques commentedI'll answer this here instead in the private emails you have sent (well I suppose you sent them, otherwise someone is busy with the same thing).
First email:
Second one:
$i is numeric.
There is the $row array which contains the data as (column_number => string_value). There is the $match array which tells us what field each column is assigned to, so this is (column_number => fieldname). Lastly there is the $header array which contains the strings in the header row as (column_number => string_value).
So for example:
$header[0] = 'a header of a column, if you want automapping to work, one would set this to title';
$match[0] = 'title';
$row[0] = 'some title data';
The code above does:
$node->title = 'some title data';
You would not change node_import.module at all. Instead you would write a support file in supported/ directory.
Something like:
This will make it so that the user is presented with a possibility to map one column to an "Imagefield: XXX". If there are multiple imagefields configured for a content type, then you probably need to add them all:
Next is to do something with it, basically the code from your other email:
Try to look at the examples in the supported/ directory.
Basically you would just create a imagefield.inc file in the supported/cck directory. It will then be automatically included in node_import.module.
The $node object in hook_node_import_prepare() has the mappings already done, so all values show up as $node->some_field_name where 'some_field_name' is the key of the array you return in hook_node_import_fields().
Let me know if you need more help,
Robrecht
Comment #2
webslinger23 commentedThanks Robrecht!
This helps a lot! I really appreciate the time you took to post here.
I ran out of time and Imported the field as a textfield and mapped to that in node_import then added the path to the output in CCK. Way suboptimal. Will give this solution a try. I'm grateful.
Comment #3
konsumer commentedYou can also do a
to get a nice associative array. This will allow you to do a
for example
array_combine
This a PHP5 function, that's useful in a lot of situations. Here is how to make an emulator:
for your original issue, I implemented this, which might be useful:
http://drupal.org/node/143471#comment-679422
Comment #4
sethcohn commentedbump - any progress on this patch? - using image attach with node_import would be useful to me right now.
Comment #5
snarlydwarf commentedSince I needed image_attach support, I added it: it is actually very easy.
Save the below code into modules/node_import/supported/image_attach.inc
You may need to adjust the pathing which is hardcoded. And maybe you want to set the title of the image node to something else... but whatever. It should be easy enough to adapt to your needs.
[oops this code didnt really work, so yanking it to not confuse people]
I don't know if I should give credit to the image module itself (where 'image_create_node_from' is), or node_import for being so easy to work with.... but the above works fine for me.
Comment #6
snarlydwarf commentedoops, I am an idiot... the above doesn't work.
this does.