Is possible create a new menu with rules?

I.E. When user create new content -> create a new menu

If not, @fago: What do you think about this feature? Is it an interesting feature to add to rules before the stable vesion?

Maybe I can help to code it.

#12 rules-menu-integration-459894-12.patch5.7 KBordermind
PASSED: [[SimpleTest]]: [MySQL] 327 pass(es). View
Members fund testing for the Drupal project. Drupal Association Learn more


fago’s picture

Category: support » feature

That makes sense to do, however I won't add any new stuff before 1.0 is out.

mitchell’s picture

Version: 6.x-1.0-rc2 » 6.x-1.x-dev
Status: Active » Postponed

Cool! I'm really looking forward to this one.

@fago: What tag would you like to start for new features, 'rules 2.0,' 'rules 1.2'?

mitchell’s picture

accidental tag

fago’s picture

Status: Postponed » Active

I'd say none. Everything that has no tag == post 1.0 - but we don't need to set it to postponed as 1.0 is out soon ;)

morbiD’s picture

Is this still in the works? I'd find such an action enormously useful.

jdln’s picture


mitchell’s picture

Title: Action: Create menu » Integration with Menu API
Version: 6.x-1.x-dev » 7.x-2.x-dev

Bumping to 7.x. Adding a few notes:

hook_menu_link_insert appears to be the function to add new menu links, and hook_menu_insert for creating new menus. The doc page for each of the other hooks that would be relevant to integrating actions and events are easy to find from there.

Two related API questions that came to mind:
- 1. How does menu_link_save relate to hook_menu_link_insert?
- 2. How would entity api fit into this? Would entity/entity-metadata be useful for conditional checks, for instance 'if a node has a primary menu link", or is it even a-whole-nother possible integration avenue, for instance by making menus and menu links into entities?

lpalgarvio’s picture

Issue tags: +menu


i would need these:
- Node menu is updated
- Node menu is created
- Node menu is deleted

to call cache_actions to clear some mini_panels (from panels) that build footer menus.

g76’s picture

I have php code for this somewhere. I can find it if anyone wants it. I am also interested in this to use through the ui without any code. Rules is incredible, just wanted to say thank you for all the hard work you make available to us all.


edit: here's the code:

$item = array(
'menu_name' => 'main-menu',
'link_path' => 'node/' . $node->nid,
'link_title' => $node->title



'Event' would be "After Saving New Content"
'Condition' would be "Content Is of Type"
'Action' would be "Execute PHP Code"

Menu weight, plid, mlid and others can be added to the code as well. Hope this helps someone.’s picture

Component: Rules Engine » Rules Core

If there was a way to unset the value, "provide menu link", I think that would be beneficial for content workflows.

i.e.: When unpublishing content that will be reviewed for deletion.

lpalgarvio’s picture

what about on Updating content event?
Do you think the node form hook gets in the way? i'm not being able to update an existing menu item (change menu parent - plid), not even with a SQL query.

        $new_mlid = 1341;

        $item =  menu_get_item("node/" . token_replace('[node:nid]', array('node' => $node)));
        $mlid = db_select('menu_links' , 'ml')
        ->condition('ml.link_path' , $item['href'])
        ->fields('ml' , array('mlid'))

        $num_updated = db_update('menu_links')
          'plid' => $new_mlid,
          'p2' => $new_mlid,
        ->condition('mlid', $mlid, '=')

        $result_sql = db_query('UPDATE `menu_links` SET `plid` = '1341', `p2` = '1341' WHERE `menu_links`.`mlid` =1396 LIMIT 1');


outputing the variables to watchdog does give me indication that i'm getting the correct mlids and plids.
editing directly on menu_links by phpmyadmin table does work

ordermind’s picture

Status: Active » Needs review
5.7 KB
PASSED: [[SimpleTest]]: [MySQL] 327 pass(es). View

Here's a patch that provides rules related to menu items and enables you to create a rule for automatic menu link creation upon node submission. It's a version of made into a submodule for Rules. Don't forget to enable the module!

My automenu replacement example looks like this:
EVENT: After saving new content
CONDITION: Node is of type (Select all node types that this rules should apply to)
CONDITION: NOT Node has menu entry
ACTION: Create a menu item for node

Importable rule:

{ "rules_automenu_replacement" : {
    "LABEL" : "Automenu replacement",
    "PLUGIN" : "reaction rule",
    "REQUIRES" : [ "rules", "menu_rules" ],
    "ON" : [ "node_insert" ],
    "IF" : [
      { "node_is_of_type" : {
          "node" : [ "node" ],
          "type" : { "value" : { "page" : "page", "panel" : "panel" } }
      { "NOT menu_rules_node_has_menu_entry" : { "nid" : "[node:nid]" } }
    "DO" : [
      { "menu_rules_create_item" : {
          "menu_name" : "main-menu",
          "menu_link_title" : "[node:title]",
          "nid" : "[node:nid]",
          "language" : "[node:language]"
mitchell’s picture

Status: Needs review » Needs work

@ordermind: Thank you for submitting this for core inclusion. I'm sure I'm not the only one with this appreciation.


I tested your project's module already with something a lot like what you have in the export. It worked well! However, imo, the best way to continue the existing pattern in Rules' codebase is to add this as a patch to and in the modules directory. Hmm, or even better to and What do you think?

ordermind’s picture

Oh, I'm not nearly knowledgeable enough about the Rules codebase pattern to make that kind of decision. At least now you have some working, structured code that you can integrate with the codebase as you see fit :)

mitchell’s picture

ordermind: I think you might be overestimating the challenge to you, but I have actually seen a pattern of contributors coming to this same conclusion. This lead me to file #1540394: Make Data API's module integrations pluggable (which I see now has a wider scope), and I haven't entirely given up on the idea, but that effort isn't likely to pick up momentum until some other large efforts are finished.

I'm very happy that the functionality exists now, so I want to thank you again. Still, it's a core API, so Rules is meant to include this functionality. I'm basing that on fago's comment in #1, among others, and asking klausi if he'd be willing to commit a patch here. He's comfortable with it. If you pick up the motivation again to work on this, I'm pretty sure you'll find that creating menu.rules/ isn't that different from an external module. Of course, someone else could pick this up too, so thanks again for getting this 3-year-old feature request going! :)

nicodv’s picture

Hi, thanks for the module, works great.

Now I have a task you could help me with: i want to tweak the module's form so that when i create a new node I also set the parent item of the future menu item and then I can use that value in the node to change the parent item in the menu_rules form.

... hope I explained myself



Cauliflower’s picture

Rustan’s picture

Issue summary: View changes
Status: Needs work » Closed (outdated)

menu_rules fills the needs of this old issue.