I have a "section" node that references child pages via an entity reference field.

I am trying to create a rule that will iterate over the referenced child nodes and create a menu item for each of them. This is working fine but I would like these child node menu items to use the parent node's menu link as their parent. Right now the direct input is a select item that can allow me to select the parent, but in this case the parent would be dynamic for every section node that is created.

How can I get a node's menu item so I can set it as the parent?

Comments

ordermind’s picture

Status: Active » Closed (won't fix)

This is a very special case, so I suggest that you use for example hook_menu_link_alter() to change the link on the fly.

Jack Ellis’s picture

I solved this by installing the Menu Node API (http://drupal.org/project/menu_node) and then:

  1. Put the Menu parent item Data Selector value as the node ID (that I wanted to be the menu parent item)
  2. PHP Evaluation with this code
    $menu_item = array_pop(menu_node_get_links($value));
    return $menu_item->menu_name.':'.$menu_item->mlid;
    

    Please note that I use a different module to have multiple menu links in the node, so you may not need the array pop.

  3. The best way to test this out is to use devel php filter and then just replace $value with a node ID (that already appears in the menu)

NOTE: If you're dynamically creating entities (or content), you will need to save the entity straight away to get the node ID. If you have problems with it not working, test and check the error log.

I didn't put too much energy into this post so I apologise if it doesn't make sense!

Whilst I'm here, I'd like to thank the maintainers for this great module!