You are here

function answers_node_view in Answers 7

Same name and namespace in other branches
  1. 7.4 answers.module \answers_node_view()
  2. 7.2 answers.module \answers_node_view()
  3. 7.3 answers.module \answers_node_view()

File

./answers.module, line 64

Code

function answers_node_view($node, $view_mode, $langcode) {
  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_instance = field_info_instance('node', 'field_answer_question', 'answer');
    $locked_p = $node->field_question_locked_p['und'][0]['value'];
    if ($locked_p == $field_instance['widget']['settings']['node_link']['full']) {
      $field_instance['widget']['settings']['node_link']['full'] = $locked_p ? +0 : +1;
      field_update_instance($field_instance);
    }
  }
}