Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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.
Comment | File | Size | Author |
---|---|---|---|
#12 | rules-menu-integration-459894-12.patch | 5.7 KB | ordermind |
Comments
Comment #1
fagoThat makes sense to do, however I won't add any new stuff before 1.0 is out.
Comment #2
mitchell CreditAttribution: mitchell commentedCool! 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'?
Comment #3
mitchell CreditAttribution: mitchell commentedaccidental tag
Comment #4
fagoI'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 ;)
Comment #5
morbiD CreditAttribution: morbiD commentedIs this still in the works? I'd find such an action enormously useful.
Comment #6
jdln CreditAttribution: jdln commentedSubscribing.
Comment #7
mitchell CreditAttribution: mitchell commentedBumping 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?
Comment #8
lpalgarvio CreditAttribution: lpalgarvio commentedinteresting
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.
Comment #9
g76 CreditAttribution: g76 commentedI 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.
Jen
edit: here's the code:
So,
'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.
Comment #10
jeremiahtre.in CreditAttribution: jeremiahtre.in commentedIf 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.
Comment #11
lpalgarvio CreditAttribution: lpalgarvio commentedwhat 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.
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
Comment #12
ordermind CreditAttribution: ordermind commentedHere'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 http://drupal.org/project/menu_rules 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:
Comment #13
mitchell CreditAttribution: mitchell commented@ordermind: Thank you for submitting this for core inclusion. I'm sure I'm not the only one with this appreciation.
odermind++
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 system.rules.inc and system.eval.inc in the modules directory. Hmm, or even better to menu.rules.inc and menu.eval.inc. What do you think?
Comment #14
ordermind CreditAttribution: ordermind commentedOh, 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 :)
Comment #15
mitchell CreditAttribution: mitchell commentedordermind: 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/eval.inc 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! :)
Comment #16
nicodv CreditAttribution: nicodv commentedHi, 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
thanks
nico
Comment #17
Cauliflower CreditAttribution: Cauliflower commentedCheck this module: http://drupal.org/project/menu_rules
Comment #18
Rustan CreditAttribution: Rustan commentedmenu_rules fills the needs of this old issue.