function forum_node_presave in Drupal 7
Same name and namespace in other branches
- 8 core/modules/forum/forum.module \forum_node_presave()
- 9 core/modules/forum/forum.module \forum_node_presave()
Implements hook_node_presave().
Assigns the forum taxonomy when adding a topic from within a forum.
File
- modules/
forum/ forum.module, line 327 - Provides discussion forums.
Code
function forum_node_presave($node) {
if (_forum_node_check_node_type($node)) {
// Make sure all fields are set properly:
$node->icon = !empty($node->icon) ? $node->icon : '';
reset($node->taxonomy_forums);
$langcode = key($node->taxonomy_forums);
if (!empty($node->taxonomy_forums[$langcode])) {
$node->forum_tid = $node->taxonomy_forums[$langcode][0]['tid'];
if (isset($node->nid)) {
$old_tid = db_query_range("SELECT f.tid FROM {forum} f INNER JOIN {node} n ON f.vid = n.vid WHERE n.nid = :nid ORDER BY f.vid DESC", 0, 1, array(
':nid' => $node->nid,
))
->fetchField();
if ($old_tid && isset($node->forum_tid) && $node->forum_tid != $old_tid && !empty($node->shadow)) {
// A shadow copy needs to be created. Retain new term and add old term.
$node->taxonomy_forums[$langcode][] = array(
'tid' => $old_tid,
);
}
}
}
}
}