7 * Node title colour chooser. Allow users to set the colour of the node title on node edit and create.
11 * Implementation of hook_form_alter().
13 function snufkin_3_form_alter(&$form, $form_state, $form_id) {
14 if (isset($form['#node']) && $form_id == $form['#node']->type .'_node_form') {
15 $form['colour'] = array(
17 '#title' => t('Title colour'),
19 '#options' => _snufkin_3_classes(),
20 '#default_value' => isset($form['#node']->colour) ? $form['#node']->colour : 'black',
21 '#description' => t('Title of this node will be rendered in this colour.'),
27 * Implementation of hook_nodeapi().
29 function snufkin_3_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
32 $node->colour = db_result(db_query('SELECT colour FROM {snufkin_3} WHERE nid = %d', $node->nid));
35 // The node is being created (inserted in the database).
36 drupal_write_record('snufkin_3', $node);
39 // The node is being updated.
40 drupal_write_record('snufkin_3', $node, 'nid');
43 // The node is being deleted.
44 db_query('DELETE FROM {snufkin_3} WHERE nid = %d', $node->nid);
47 drupal_add_css(drupal_get_path('module', 'snufkin_3') . '/snufkin_3.css');
48 drupal_set_title(theme('colourized_title', $node));
54 * Implementation of hook_theme().
56 function snufkin_3_theme() {
58 'colourized_title' => array(
59 'arguments' => array('node' => NULL),
60 'file' => 'snufkin_3.theme.inc',
66 * Helper function to return a list of colour classes used in the title.
69 * Array keyed with class names, values are translated, user-friendly names.
71 function _snufkin_3_classes() {
74 'black' => t('Black'),
77 'green' => t('Green'),