function discussthis_node_validate in Discuss This! 7
Same name and namespace in other branches
- 7.2 discussthis.node.inc \discussthis_node_validate()
Implements hook_node_validate().
File
- ./
discussthis.node.inc, line 154 - File with node discussion display methods.
Code
function discussthis_node_validate($node, $form) {
if ($node && user_access('override discuss this forums') && isset($node->discussthis)) {
if (!empty($node->discussthis['discussthis_topic'])) {
$topic_nid = $node->discussthis['discussthis_topic'];
// valid integer?
// and if valid, is that this very node? if so, that's not good either
if ($topic_nid == (int) $topic_nid && !is_null($node->nid) && $topic_nid != $node->nid && is_numeric($topic_nid)) {
// make sure we can actually load that node and that's a forum's node
$topic = node_load((int) $topic_nid);
if (!$topic || $topic->type != 'forum') {
$topic_nid = FALSE;
}
}
else {
$topic_nid = FALSE;
}
if (!$topic_nid) {
// ugly error setting which works
form_set_error('discussthis][discussthis_topic', t('The Discuss This! forum topic #@nid was not found (or you chose this very node.) Please, try again. Use the auto-complete feature or enter the exact node identifier. If you did not change the topic identifier, it could have been deleted while you were editing this node. Simply clear the topic entry in that case.', array(
'@nid' => $node->discussthis['discussthis_topic'],
)));
unset($node->discussthis['discussthis_topic']);
}
}
// the forum should never be wrong with a select unless we're working with a hacker
if (!empty($node->discussthis['discussthis_forum'])) {
// valid integer? representing a valid forum?
$forum_tid = $node->discussthis['discussthis_forum'];
if ((int) $forum_tid != -1) {
if ($forum_tid == (int) $node->discussthis['discussthis_forum']) {
$vid = variable_get('forum_nav_vocabulary', '');
$term = taxonomy_term_load($forum_tid);
if (!$term || $term->vid != $vid) {
form_set_error('discussthis][discussthis_forum', t('The Discuss This! forum #@tid was not found.', array(
'@tid' => $forum_tid,
)));
unset($node->discussthis['discussthis_forum']);
}
}
else {
unset($node->discussthis['discussthis_forum']);
}
}
}
}
}