1

I have a simply question, it's possible to delete a node and at the same time delete a menu_links ? For exemple when i will use the button delete of a node of my entity "PROJECT" i want to delete automaticaly a menu_links created before. I found the HOOK_Delete but how to use this function in a particular entity ? Like the HOOK_form_alter we can choose the form_id, there is a HOOK like this ? :

Mymodule_delete($nid) {
    if($entity == "project") {
        delete($nid);
    }
}

Maybe can i change the $form['actions']['delete ??'] in my form alter and use my own function ?

_myfunction_delete_project($nid) {
    $query = "Here get the entity of my $nid";

    if($query == "project") {
        delete($nid);
        delete($my menu links);
    }
}

I hope you understand my request

Thanks

3
  • 1
    No need to write any custom code for this. I think menu link automatically got deleted when you delete any entity. Commented Dec 3, 2014 at 11:43
  • Ok, i want to delete a menu link not bonded with my entity, to explain, when i add an entity "Project" i create a special menu link in my menu with "menu_link_save" but when i delete this entity i want to delete the menu_links created before. They are not bonded together.
    – Cracs
    Commented Dec 3, 2014 at 12:51
  • Check my answer.. :) Commented Dec 3, 2014 at 12:54

1 Answer 1

0

You can do it simply using hook_node_delete.

function hook_node_delete($node) {
  if ($node->type == 'any_content_type') { // for specific content type
    // here your code use $node->nid
  }
}
2
  • Thanks ! It's what i'm searching ! i didn't know we can check the type of node in $node :)
    – Cracs
    Commented Dec 3, 2014 at 13:03
  • Glad it helps... :) Commented Dec 3, 2014 at 13:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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