You are here

function answers_node_view in Answers 7.3

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

Implements hook_node_view().

File

./answers.module, line 107

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 = answers_field_get_value($node, 'field_question_locked_p');
    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);
    }
  }
  elseif ($node->type == 'answer' && variable_get('answers_redirect_from_answer_to_question_nodes_p', TRUE) && $view_mode == 'full' && node_is_page($node) && $node->status) {

    // If viewing the node page for a published answer and if configured to use
    // theme templates, then redirect to question, with answer node id in
    // fragment.
    $items = field_get_items('node', $node, 'field_answer_question', $node->language);
    if (!empty($items[0]['nid'])) {
      drupal_goto('node/' . $items[0]['nid'], array(
        'fragment' => 'node-' . $node->nid,
      ));
    }
  }
}