0

I have a feed importer for image files, which stores a column in my source csv as the GUID of the final files in Drupal.

I also have another importer for, say, articles. In the articles csv, there is an "image key" column, that corresponds to the image GUIDs mentioned above.

I'm working on a custom feeds tamper plugin that can convert the GUIDs to the image URIs that have already been imported by the first importer, but I'm completely lost on how to retrieve the images in the code.

So, the question is: how do I convert an previously imported image file GUID into the actual image's URI?

1 Answer 1

0

I came up with a solution, simply using a DB query to get what I want. Here is the callback for the tamper module. Hopefully someone will find a better solution, if it's possible.

function myfeedsmodule_tamper_imagekey_callback($result, $item_key, $element_key, &$field, $settings) {
  $field = trim($field);
  if ($field == 'NULL') {
      $field = NULL;
      return;
  }
  $result = db_select('feeds_item', 'f')
          ->fields('f', array('entity_id'))
          ->condition('guid', $field, '=')
          ->condition('entity_type', 'file', '=')
          ->condition('id', 'my_image_importer', '=')
          ->execute()
          ->fetchField();
  if (!$result) {
      $field = NULL;
      return;
  }
  $entities = entity_load('file', array($result));
  if (!$entities) {
      $field = NULL;
      return;
  }
  $image = current($entities);
  $field = $image->uri;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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