You are here

function auto_nodetitle_nodeapi in Automatic Nodetitles 5

Same name and namespace in other branches
  1. 6 auto_nodetitle.module \auto_nodetitle_nodeapi()

Implementation of hook_nodeapi().

Sets the node title. To let node previews work this is also done during node validation.

File

./auto_nodetitle.module, line 48
Allows hiding of the node title field and automatic title creation

Code

function auto_nodetitle_nodeapi(&$node, $op, $form = NULL, $a4 = NULL) {
  if ($op == 'validate' && $form['#post']['op'] == t('Preview') && auto_nodetitle_is_needed($node)) {

    // As changes to $node are not persistent during validation, we use form_set_value()!
    auto_nodetitle_set_title($node);
    form_set_value($form['title'], $node->title);
  }
  else {
    if ($op == 'submit' && auto_nodetitle_is_needed($node)) {
      auto_nodetitle_set_title($node);
    }
  }
}