function answers_nodeapi in Answers 6.2
Same name and namespace in other branches
- 5.2 answers.module \answers_nodeapi()
- 6 answers.module \answers_nodeapi()
Implements hook_nodeapi().
File
- ./
answers.module, line 66
Code
function answers_nodeapi(&$node, $op, $teaser, $page) {
global $user;
switch ($op) {
case 'view':
if ($node->type == 'question') {
// Ensure that the 'Post an Answer' link only shows if the question is not locked
// The logic is a little complicated below to avoid updating the field when not necessary
// The field should have the *opposite* value of the node->locked field
$field = content_fields('field_answer_question', 'answer');
$locked_p = $node->field_question_locked_p[0]['value'];
if ($locked_p == $field['widget']['node_link']['full']) {
module_load_include('inc', 'content', 'includes/content.crud');
$field['widget']['node_link']['full'] = $locked_p ? +0 : +1;
content_field_instance_update($field);
}
}
break;
case 'delete':
if ($node->type == 'question') {
$answer_nids = _answers_question_answers($node);
foreach ($answer_nids as $answer_nid) {
node_delete($answer_nid);
}
}
break;
}
_answers_display_nodeapi($node, $op, $teaser, $page);
_answers_notify_nodeapi($node, $op, $teaser);
}