0

While creating a new node, I'd like to pass a parameter in the URL: node/add/page?plid=123 in order to put the newly created node in this menu item as its child.

I tried to hook_form_alter() the node form but I couldn't populate the menu part, also I'd like to hide this part to the end user as they shouldn't alter it.

Should this be done in a hook_node_insert() with something like this answer: How to enable menu link when creating a new node ?

1 Answer 1

1

hook_node_insert() is probably the place to do this. You'll want to call menu_link_save() to create the menu item, using the $_GET superglobal to retrieve the plid parameter.

function mymodule_node_insert($node) {
  $item = array(
    'link_path' => 'node/' . $node->nid,
    'link_title' => $node->title,
    'plid' => $_GET['plid'],
  );
  if (!menu_link_save($item)) {
    // It has not been possible to save the menu item.
    // Handle this failure case.
  }
}
0

Your Answer

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

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