function forum_node_presave
Same name in other branches
- 9 core/modules/forum/forum.module \forum_node_presave()
- 8.9.x core/modules/forum/forum.module \forum_node_presave()
- 10 core/modules/forum/forum.module \forum_node_presave()
- 11.x 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
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,
);
}
}
}
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.