Hello everyone!

I am developing a module that adds a new type of content. So far it's working fine, but the thing is that I don't want, when adding new content of this type, that it becomes promoted to the front page. I would like it to be like the forums, which is a module that extends the node type, and when you post a new thread it does not appear in the front page.

I am trying to find out how the forums module does it, but so far I have not found it.

Anyone knows how to do it?

Thanks in advance.

Comments

xano’s picture

It's done manually at /admin/content/types. Just edit the content type of your choice and uncheck the option to promote nodes of that type by default.

jsabater’s picture

Erm... thanks, but I already knew that. :)
What I'd like to do is to do that automatically when the module is installed.

KingMoore’s picture

There may be a better way to do this, but I have done it in hook_form_alter, by manually setting the values for the options like this:

function hook_form_alter($form_id, &$form){

  //please don't promote my types to front page
  if($form['type']['#value'] == 'my_ctype'){
    $form['options']['promote']['#default_value'] = 0;
  }
}

You can do the same thing for the other options you want to change. With this method a user could still choose to tick the boxes, but it changes the default values.

jsabater’s picture

I must be doing something wrong, but I created the following and does not seem to work:

<?php
function hook_form_alter(&$form, $form_state, $form_id) {
    // Do not promote characters to front page
    $form['options']['promote']['#default_value'] = 0;
    unset($form['options']['promote']);
}
?>

Not that I have both options at the same time, but I tried first with one, then with the second, and neither do anything. I've tried disabling and uninstalling the module, then installing it again.

What may I be missing? If I create content with the admin, the option appears whether I use any of the two sentences above in the function, but perhaps that is because I am the admin. But as a normal user, despite of the fact that I do not get the ability to see or alter that checkbox, the node (character) is being promoted to the front page (in both cases as well).

Also, I checked the forums module and it does not seem to have anything like that to get rid of it (I did a grep on the whole directory).

Thanks for your help.

P.S. By the way, using Drupal 6.1 here.

xano’s picture

Hooks are implemented like MODULENAME_HOOKNAME(). The word 'hook' must not occur in the function's name.

jsabater’s picture

My fault, sorry. I knew that, but made a typo with the copy-paste thing. Thanks for the help. Much appreciated. :)