0

Good day

I have a problem with the side of developer

with certainly conditions i need remove a item from source. for example i have in source

nid and phone1 and phone2

but if phone2 is the same that phone1 remove, all this is in updates nodes

function custom_feeds_before_update($source, $item, $entity_id){

  $entity = node_load($entity_id);
   if (isset($item['phone 2'])) { 
      if($entity->field_phone_1['und'][0]['value'] == $item['phone 2']){
         unset($item['phone 2']);
      }
  }
}
function custom_feeds_presave($source, $item, $entity_id){

  $entity = node_load($entity_id);
   if (isset($item['phone 2'])) { 
      if($entity->field_phone_1['und'][0]['value'] == $item['phone 2']){
         unset($item['phone 2']);
      }
  }
}

something i make wrong? none working never unset if i make dpm in item no appear the item but if i see the node appear update, is other hook

thanks for any help

  • Are these two functions actual Drupal hook functions? Documentation shows otherwise. Also is this D7 or D8? – cchen Sep 12 '18 at 18:17
  • is for drupal 7 – jonathan Sep 13 '18 at 14:53
  • okay are these two functions actual Drupal hook functions? – cchen Sep 13 '18 at 15:07
  • yes hook_feeds_presave and hooks_feeds_before_update – jonathan Sep 13 '18 at 18:39
1

To alter the source items for the D7 version of Feeds, implement the hook hook_feeds_after_parse().

/**
 * Implements hook_feeds_after_parse().
 *
 * Removes duplicate phone numbers for importer 'myimporter'.
 */
function mymodule_feeds_after_parse($source, $result) {
  if ($source->importer->id == 'myimporter') {
    foreach ($result->items as &$item) {
      if (isset($item['phone 1']) && isset($item['phone 2']) && $item['phone 1'] == $item['phone 2']) {
        // If phone 1 and phone 2 are the same, do not import phone 2.
        unset($item['phone 2']);
      }
    }
  }
}

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.