Hi all, I was working on an import and I realised that isbn did not integrate with feeds. I have prepared a patch to add this functionality. It works just fine for me, can somebody have a look?

Comments

denix created an issue. See original summary.

denix’s picture

denix’s picture

StatusFileSize
new1.71 KB

sorry, the patch was not working properly. now it should be fixed

rfsbsb’s picture

Status: Needs review » Needs work

Hi @denix,

Thanks for the patch. There's a forgotten `dpm($entity);` on your patch. Please fix it and submit it again.

Thanks.

denix’s picture

StatusFileSize
new1.69 KB

Hi @rfsbsb,
thank you for spotting this.
The attached file is the patch for 7.x-1.x git version, if somebody is interested into use feeds with version 7.x-1.0 then just copy this code into a new file called isbn.feeds.inc:


/**
 * @file
 * Provides integration with Feeds module (http://drupal.org/project/feeds).
 */

/**
 * Implements hook_feeds_processor_targets().
 */
function isbn_feeds_processor_targets($entity_type, $bundle) {
    $targets = array();

    foreach (field_info_instances($entity_type, $bundle) as $name => $instance) {
        $info = field_info_field($name);

        if ($info['type'] == 'isbn') {
            $targets[$name] = array(
                'name' => check_plain($instance['label']),
                'callback' => 'isbn_feeds_set_target',
                'description' => t('The @label field of the node.', array('@label' => $instance['label'])),
            );
        }
    }

    return $targets;
}

/**
 * Callback to set target value.
 */

function isbn_feeds_set_target(FeedsSource $source, $entity, $target, array $values, array $mapping) {
    $language = $mapping['language'];

    $field = isset($entity->$target) ? $entity->$target : array($language => array());

    // Iterate over all values.
    foreach ($values as $value) {
        if (is_object($value) && ($value instanceof FeedsElement)) {
            $value = $value->getValue();
        }
        $field[$language][] = array('isbn' => preg_replace('/([^xX0-9]*)/', "", $value));
    }

    $entity->$target = $field;
}
denix’s picture

Status: Needs work » Needs review
thorn’s picture

I can confirm that the patch works.

denix’s picture

Status: Needs review » Reviewed & tested by the community
rfsbsb’s picture

Hi @denix,

Thanks for you work on this patch. I'll review it later today and if it's working, I'll merge it.

Thanks a lot

  • rfsbsb committed fdcbc81 on 7.x-1.x authored by denix
    Issue #2842995 by denix: ISBN Feeds import integration
    
rfsbsb’s picture

Status: Reviewed & tested by the community » Fixed

Thanks guys, code committed.

Status: Fixed » Closed (fixed)

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