2

I'm using Feeds import module, after importing CSV file, if a row doesn't match content type validation the feeds import saves that node with empty space in that field.

Question: Now i want FeedsNodeProcessor to validate the node, and if there is a empty space it should throw error for that node or should not create node for that row.

Example: If i have 40 rows in an excel and 39 rows satisfies the conditions of content type and only 1 row doesn't then it has to like this, 39 nodes created.

Updated: i have added hook_feeds_prevalidate() in my hook_form_alter module.

 function tracker_custom_form_alter(&$form, &$form_state, $form_id) {
   if($form_id == 'orientation_node_form'){
      $form['#validate'][] = 'validate_orientation';
}
}
function validate_orientation($form,&$form_state)
{
....
}
function tracker_custom_feeds_prevalidate($source, &$entity, &$item, $entity_id) {
//      dpm($entity->feeds_item->id); - its not printing anything.
//      dpm($item); - its not printing anything.
  if ($entity->feeds_item->id == 'bulk_upload') {
     if (empty($item['Billing Type'])) {
         $entity->feeds_item->skip = TRUE;
         drupal_set_message('ksdhbf');
   }
 }
}
2
  • 1
    Drupal version? – No Sssweat Oct 30 '19 at 11:56
  • I am using Drupal 7 – Harish Nov 5 '19 at 11:11
1

You can add this functionality in a custom module. But you'll have to add the logic that you have in your node's validation here.

/*
 * Implements hook_feeds_prevalidate()
 */
function mymodule_feeds_prevalidate($source, &$entity, &$item, $entity_id) {
  // the $item contains your csv files column values
  if ($entity->feeds_item->id == 'import_name') { // check the feed import ID
    if ($item['some column'] != 'something') { // validate column value
      $entity->feeds_item->skip = TRUE; // skips this row from importing
    }
  }
}

Important: I think you'll need 7.x-2.x-dev in order for this hook to work, I'm using it. This is a new hook and I think it has not been added to 7.x-2.0-beta4 yet.

0

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.