Hi,
i want to start building a drupal module, but have totally no experience with this.
First of all i choose to build it for d5 first, then if it works fine rebuild for d6. I think there are still many d5-ers.
What i want to do?
I want to make a module that places a new setting on every 'add new content type' page.
This setting has to be a yes/no choise for applying the module to this content type.
If applied, on every 'submit new node' page for the applied content type there has to be a dropdown with numbers from 1 to 10.
This way, moderators can give a value to that node.
I would like to build the module by myself, but i would love if someone could point me to a good direction.
I have many module-ideas, but have to start somewhere ;)
Hope somebody could help me out.
many thanks in advance,
tom
Comments
best way I find
...is to find a user contributed module that does something sort of like what you want to do (i.e. modifies the 'add new content type' page), install it, and look at the code to figure out how it works.
Heck, even the built in comment module uses hook_form_alter to alter that form. (I'm looking at D6 code):
function comment_form_alter(&$form, $form_state, $form_id) {
if ($form_id == 'node_type_form' && isset($form['identity']['type'])) {
$form['comment'] = array(
'#type' => 'fieldset',
'#title' => t('Comment settings'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
If you're really just getting started I highly recommend the "pro drupal development' book, first edition for d5, second for d6.
Thanx for your quick
Thanx for your quick reply.
I've made some piece now, but i'm stuck, could someone look at my code please?
the radio-list on the content-type form works, the setting is saved in as a variable
the select field on the node form shows depending on the contenttype setting
this works, but...
the select on the nodeform doesnt saves or loads the default.
Thats where i'm stuck.
Please help me, i'm already this far (in my opinion off coarse ;))
this is my code:
function nodexperience_form_alter($form_id, &$form) {
if ($form_id == 'node_type_form') {
$form['workflow']['nodexperience'] = array(
'#type' => 'radios',
'#title' => t('Nodexperience settings'),
'#parents' => array('nodexperience'),
'#default_value' => nodexperience_get_setting($form['#node_type']->type),
'#description' => t('When enabled, you can give a experience level value
to the node.'),
'#options' => array(t('Disabled'), t('Enabled')));
}
if (isset($form['#node']) && isset($form['#post']) && $form['#node']->type .'_node_form' == $form_id) {
//this is a node form
if (nodexperience_get_setting($form['#node']->type) == "1") {
$options = array(0 => t('Unrated'), 1, 2, 3, 4, 5);
$form['nodexperience'] = array(
'#type' => 'select',
'#title' => t('Experience level'),
'#default_value' => $node->nodexperience,
'#description' => t('Give this node a experience level'),
'#options' => $options,
'#weight' => 0,
);
}}}
function nodexperience_nodeapi(&$node, $op, $form = NULL, $a4 = NULL) {
switch ($op) {
case 'update':
if ($node->nid && $node->moderate) {
// Reset votes when node is updated:
$node->nodexperience = 3;
}
break;
}}
/**
* Gets the nodexperience title setting associated with the given content type.
*/
function nodexperience_get_setting($type) {
return variable_get('nodexperience_'. $type, AUTO_NODETITLE_DISABLED);
}
sorry, can help you out there
I highly recommend you checkout:
http://drupal.org/project/Modules/category/60
expecially the 'fivestar' voting module. I just installed it and it adds a section to the 'add content type' page.
please?
please?
Try something like this. If
Try something like this. If you look carefully, I'm using variable_get in the default value.
http://api.drupal.org/api/function/variable_get/5
Good luck.