You are here

function auto_nodetitle_set_title in Automatic Nodetitles 6

Same name and namespace in other branches
  1. 8 auto_nodetitle.module \auto_nodetitle_set_title()
  2. 5 auto_nodetitle.module \auto_nodetitle_set_title()
  3. 7 auto_nodetitle.module \auto_nodetitle_set_title()

Sets the automatically generated nodetitle for the node

3 calls to auto_nodetitle_set_title()
auto_nodetitle_nodeapi in ./auto_nodetitle.module
Implementation of hook_nodeapi().
auto_nodetitle_node_form_submit in ./auto_nodetitle.module
Makes sure the node preview is shown right. It gets the node object, modifies the title, and updates the node in the form_state.
auto_nodetitle_operations_update in ./auto_nodetitle.module
Callback function for updating node titles.

File

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

Code

function auto_nodetitle_set_title(&$node) {
  $types = node_get_types();
  $pattern = variable_get('ant_pattern_' . $node->type, '');
  if (trim($pattern)) {
    $node->changed = time();
    $node->title = _auto_nodetitle_patternprocessor($pattern, $node);
  }
  else {
    if ($node->nid) {
      $node->title = t('@type @node-id', array(
        '@type' => $types[$node->type]->name,
        '@node-id' => $node->nid,
      ));
    }
    else {
      $node->title = t('@type', array(
        '@type' => $types[$node->type]->name,
      ));
    }
  }

  // Ensure the generated title isn't too long.
  $node->title = substr($node->title, 0, 255);

  // With that flag we ensure we don't apply the title two times to the same node.
  $node->auto_nodetitle_applied = TRUE;
}