1

When creating content, I would like to force the checkbox "Provide a menu link" to be checked by default.

What I'm really trying to do:

  • I created a new content type
  • I used node_add to get the form associated to my content type and render it into my template.
  • In my module I used the hook_form_alter to hide some fields of my form.

But when the user submit the form and the node is created, there is no menu link created by default.

3

I looked everywhere for this! The Menu Force module does this:

This module enables you to make the Menu Settings required on specific content types.

After installing a "Make the Menu Settings mandatory for this content type" tick box becomes available on the settings for each content type.

2

Use hook_form_alter to set the #default_value of the Provide a menu link checkbox to true.

  • There is no "Provide a menu link" item in the "$form" object of "hook_form_alter". – FR6 Dec 16 '11 at 19:10
2

I solved my problem.

To force the creation of a menu link I used the hook function hook_node_insert:

function *MODULE*_node_insert($node){
        if($node->type == '*CONTENT TYPE*'){
            $node->menu['enabled'] = true;
            $node->menu['link_title'] = $node->title;
        }
} 
-1

Simple install https://www.drupal.org/project/default_menu_link and there you go.

There is a similar module called Menu Force that does just that. Whereas Menu Force mandates menu assignment, Default Menu Link merely changes the status of "Provide a Menu Link" to true. The user can still create content and choose to un-check this box. However, the default state (on node creation) will be true, and as long as you've set a default menu parent item, all content will be filed under that parent.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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