I have configured a field collection field (unlimited items) for a content type and I want create a confirm popup when user delete an item. For this, i found that i can directly go and modify 2 functions in the field_collection.pages.inc file. They are:

1. field_collection_item_delete_confirm

2. field_collection_item_delete_confirm_submit

I'm a newbie in drupal so I don't know how to use these function from the field_collection.pages.inc file, I tried to hook these function in template.tpl file but it's didn't work. Can someone help me ? Sorry about my English.

  • Popup over the same form? You should do that with jQuery. Intercept click event, display popup (which will depend on your theme) and take action. Get jQuery script and popup html into the form with hook_form_alter. – J. Reynolds Mar 9 '16 at 5:00
  • Yes. Popup over the same form. I tried to do this with my solution: - Use hook_field_widget_form_alter() to create a new button - put over a remove button and a div to show message confirm, then I attached the .js file to this hook. - When I click the confirm button in Confirm div popup, I'll create a new event for the old button. Ex: $('the-old-button').click() Note: Before I tried my solution, when I click remove button in field collection content type, it's remove immediately by ajax. I'm not sure you will understand my word because I'm my english is not good. – Phat Le Mar 9 '16 at 6:40

Here is what i did, to handle the deletion of a field collection item for a node:

  • Created a hook of type hook_node_view() in my custom module and overridden the delete link for the field collection items, so that they point to a custom path, that is declared in my custom modules hook_menu().
  • Now the custom path is mapped to a template file (passing the field collection item id).
  • The logic inside the tpl file processes the deletion of field collection item (passed by id) using entity_delete_multiple() and sets a custom message to be displayed back to the node view page.

more details

  • Thanks for reply ! You'll save my life if you explain this solution more detail. I work with Drupal just a few day so it will take a long time for me to research, but my deadline is today. – Phat Le Mar 9 '16 at 6:52

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.