Hi,
I am trying to build a Drupal site where the node title is computed by adding some existing CCK fields, and it's really a big pain.
I have found the auto node title module, wich already does half of what I need. This code hides the title form fields from the node types I choose, and it changes the node title to the content type.
Instead of the content type, I want the title to be 3 custom fields, I already managed displaying this title in the a views page with this code:
<h2 class="review"><a href="<?php print $url; ?>"><?php print $field_year_value;?> <?php print $term_node_1_name; ?> <?php print $field_model_designation_value; ?></a></h2>
However, using the method only gives me more problems and inconsistencies. So hopefully I can change the module code below to use my CCK fields rather then content type for a title.
I have some experience messing around with php code, but the code below that generates $title is beyond me, I don't get what's going on with the % signs.
If someone could point me into the right direction or help me change this code it would be greatly appreciated!
JR
// $Id: auto_nodetitle.module,v 1.3 2006/08/29 12:24:11 fago Exp $
/**
* @file
* Allows hiding of the node title field and automatic title creation
*/
/**
* Implementation of hook_help().
*/
function auto_nodetitle_help($section) {
switch ($section) {
case 'admin/modules#description':
return t('Allows hiding of the node title field and automatic title creation.');
}
}
/*
* Implementation of hook_form_alter().
*/
function auto_nodetitle_form_alter($form_id, &$form) {
if (isset($form['type']) && $form['type']['#value'] .'_node_settings' == $form_id) {
$form['submission'][$form['type']['#value'] .'_auto_nodetitle'] = array(
'#type' => 'checkbox',
'#title' => t('Automatically generate the node title and hide the node title field.'),
'#weight' => -5,
'#default_value' => variable_get($form['type']['#value'] .'_auto_nodetitle', 0),
);
}
else if (isset($form['type']) && $form['type']['#value'] .'_node_form' == $form_id) {
//this is a node form
if (variable_get($form['type']['#value'] .'_auto_nodetitle', 0)) {
$types = node_get_types();
//node id is only available for node updates
$title = ($form['#node']->nid) ? t('%type %node-id', array('%type' => $types[$form['type']['#value']], '%node-id' => $form['#node']->nid)) :
t('%type', array('%type' => $types[$form['type']['#value']]));
$form['title'] = array('#type' => 'value', '#value' => $title);
}
}
}