0

I am trying to setup a Feed Import from CSV. There is an images field in the content type which can have unlimited values. These images are in a folder and named in the following format:

[identifier_from_csv]_01_large.jpg 
[identifier_from_csv]_02_large.jpg 
[identifier_from_csv]_03_large.jpg

Each project has a variable number of images. I would like to be able to read from the file system and import as many images it has located there. I've tried to research into this and from what I can see the Feeds Tamper module I would still have to know how many images there are and have them all listed in a field.

How can I setup an import that would automatically read in as many images as there are located in the file import directory? I'm assuming there is a hook I could use and loop through there checking the file system, I'm not sure where/how to implement that.

0

I ended up solving this myself. My main question I guess was really about a feeds tamper plugin that can insert multiple values. Turns out it's pretty easy, just return an array and I think set the 'multi' value on the plugin. I ended up copying the "explode" plugin and modifying it for my needs. Here is the result. It's got some hardcoded values which I'm sure could be coded into the form settings. I kept it simple for my purposes.

$plugin = array(
    'form' => 'my_feeds_tamper_image_import_form',
    'callback' => 'my_feeds_tamper_image_import_callback',
    'validate' => 'my_feeds_tamper_image_import_validate',
    'name' => 'My Image Import',
    'multi' => 'direct',
    'category' => 'List',
);


function my_feeds_tamper_image_import_form($importer, $element_key, $settings) {
    $form = array();
    return $form;
}

function my_feeds_tamper_image_import_validate(&$settings) {

}

function my_feeds_tamper_image_import_callback($result, $item_key, $element_key, &$field, $settings, $source) {
    $out = array();
    $index = 1;
    $fileExists = true;

    do {
        $filename = "public://import/" . $field . "_" . str_pad($index, 2, "0", STR_PAD_LEFT) . "_lg.jpg";

        if( file_exists($filename) ) {
            $out[] = $filename;
            $index++;
        }
        else {
            $fileExists = false;
        }

    } while($fileExists);

    $field = $out;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.