function answers_lock_example_node_presave in Answers 7.4
Implements hook_node_presave().
When a new question is saved, if the configuration is set to lock questions, then set the question lock. Here, we could use "answers_reset_question_lock", however it is faster to simply call "answers_lock_question" to set the lock.
However, neither of those functions can be used within hook_node_insert because they call node_save, resulting in an infinite loop. So, here, we simply set the question lock field directly (generally not the best practice).
File
- answers_lock_example/
answers_lock_example.module, line 115 - Example module of the question 'lock'.
Code
function answers_lock_example_node_presave($node) {
if ($node->type == 'answers_question' && variable_get('answers_lock_example_lock_questions_p', 0)) {
$lang = field_language('node', $node, 'question_locks');
$node->question_locks[$lang][0]['value'] = 'answers_lock_example';
}
}