0

I have create a module and I am using the following hook implementation.

The code works on success, but how do I prevent or stop further processing when I get failed as status?

mymodulename_field_collection_item_delete($field_collection_item) {
   $itemID = entity_id('field_collection_item', $field_collection_item);
   $fc = entity_load_single('field_collection_item', $itemID );
   $pid = $fc->field_product_guid['und'][0]['value'];
   $responseAPI = json_decode(deleteProductRequestAPI($pid,"DELETE"), true);
   if($responseAPI['status']=='success'){
     drupal_set_message(t('Is successfully deleted.'));
   }else{
     drupal_set_message(t('Failed to deleted.'));
   }
   die;
}
// here curl request sending 
functin deleteProductRequestAPI($pid,$method){
  // here i have written code for send request and will
  // get response in status as "success" or "failed".
}

The field Collection name is Products and the content type is Brands.

  • It’s already being deleted at this point. You have to do the API call before the delete is invoked and work the logic that way. – Kevin Dec 20 '18 at 15:33
  • Can i know the hook before deleting field collection item so that i will trigger there and implement my logic.. – ramanaraju.s Dec 20 '18 at 15:36
0

What you should do instead of an API call on delete is create a job with the QueueAPI in Drupal to create a job for processing later. In that job, pull the ID from the record (stored in the job) and do the API call. If the status failed, requeue the job.

I can’t write all the code out for you but there are plenty of QueueAPI examples for D7 out there.

https://api.drupal.org/api/drupal/modules%21system%21system.queue.inc/group/queue/7.x

and

https://rbayliss.com/blog/drupal-queue-api/

Are great starting points.

You could then create a custom Drush command that processes these jobs as fast as you desire. Note the section in rovs post that deals with “failed” states of a job and not removing it from the queue. That is key.

This will let Drupal function normally and defer errors in the remote system to you to work through.

  • May i know the hook which triggers before deletion of field collection item. So that i can get that particular item all information. – ramanaraju.s Dec 28 '18 at 9:27
  • Did you even read what I posted? – Kevin Dec 28 '18 at 12:46

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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