From 95a35df6350124da0a32d287c77080e2a04fd0f3 Mon Sep 17 00:00:00 2001
From: chipcleary <chipcleary@hotmail.com>
Date: Sat, 3 Mar 2012 16:25:57 -0600
Subject: [PATCH] 1371588 by hefox, chipcleary: Remove navigation to answer node

---
 answers.install              |    8 +++++++-
 answers.module               |   30 ++++++++++++++++++++++++------
 includes/answers.display.inc |   39 +++++++++++++++++++++++++++++++++++++++
 node-answer.tpl.php          |   31 +++++++++++++++++++++++++++++++
 4 files changed, 101 insertions(+), 7 deletions(-)
 create mode 100644 includes/answers.display.inc
 create mode 100644 node-answer.tpl.php

diff --git a/answers.install b/answers.install
index 1bb9164..38c6582 100644
--- a/answers.install
+++ b/answers.install
@@ -114,4 +114,10 @@ function _answers_field_question_locked_p() {
     ),
   );
   return $array;
-}
\ No newline at end of file
+}
+
+function answers_update_6201() {
+  watchdog('answers', 'Enable answers theming');
+  drupal_rebuild_theme_registry();
+  return array();
+}
diff --git a/answers.module b/answers.module
index 8d7cea5..e24cd0e 100644
--- a/answers.module
+++ b/answers.module
@@ -1,9 +1,10 @@
 <?php
 
 include_once('answers.features.inc');
-module_load_include('inc', 'answers', 'includes/answers.search');
-module_load_include('inc', 'answers', 'includes/answers.notify');
+module_load_include('inc', 'answers', 'includes/answers.display');
 module_load_include('inc', 'answers', 'includes/answers.lock');
+module_load_include('inc', 'answers', 'includes/answers.notify');
+module_load_include('inc', 'answers', 'includes/answers.search');
 
 /**
  * Implements hook_help().
@@ -53,6 +54,7 @@ function answers_menu_alter(&$items) {
  * Answer administer settings form definition.
  */
 function answers_settings() {
+  $form['display'] = _answers_display_settings();
   $form['notify'] = _answers_notify_settings();
   return system_settings_form($form);
 }
@@ -61,11 +63,9 @@ function answers_settings() {
  * Implements hook_nodeapi().
  *
  */
-function answers_nodeapi(&$node, $op, $teaser) {
+function answers_nodeapi(&$node, $op, $teaser, $page) {
   global $user;
 
-  _answers_notify_nodeapi($node, $op, $teaser);
-
   switch ($op) {
 
     case 'view':
@@ -79,7 +79,7 @@ function answers_nodeapi(&$node, $op, $teaser) {
         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);
+          content_field_instance_update($field);
         }
       }
       break;
@@ -94,6 +94,10 @@ function answers_nodeapi(&$node, $op, $teaser) {
       break;
 
   }
+
+  _answers_display_nodeapi($node, $op, $teaser, $page);
+  _answers_notify_nodeapi($node, $op, $teaser);
+
 }
 
 /**
@@ -186,3 +190,17 @@ function answers_field_access($op, $field, $account, $node = NULL) {
   }
   
 }
+
+/**
+ * Implements hook_theme_registry_alter
+ * 
+ * Have drupal look in the module for content-type override templates
+ */
+function answers_theme_registry_alter(&$theme_registry) {
+  $template = 'node';
+  $originalpath = array_shift($theme_registry[$template]['theme paths']);
+  $modulepath = drupal_get_path('module', 'answers');
+  // Stick the original path with the module path back on top
+  array_unshift($theme_registry[$template]['theme paths'], $originalpath, $modulepath);
+}
+
diff --git a/includes/answers.display.inc b/includes/answers.display.inc
new file mode 100644
index 0000000..3d185fb
--- /dev/null
+++ b/includes/answers.display.inc
@@ -0,0 +1,39 @@
+<?php
+
+/**
+ * @file
+ * Display utility functions for the 'Answers' module
+ */
+
+/**
+ * Add settings relating to display to the admin form
+ */
+function _answers_display_settings() {
+  $form = array();
+
+  $form['answers_display'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Display Settings'),
+  );
+
+  $form['answers_display']['answers_redirect_from_answer_to_question_nodes_p'] = array(
+    '#type'          => 'checkbox',
+    '#title'         => t('Redirect paths from answers to questions'),
+    '#default_value' => variable_get('answers_redirect_from_answer_to_question_nodes_p', TRUE),
+    '#description'   => t('This will redirect from showing answer nodes in page view to instead showing the question node in page view, scrolling down to the answer. (Recommended)'),
+  );
+
+  return $form;
+}
+
+function _answers_display_nodeapi(&$node, $op, $teaser, $page) {
+  if (($op == 'view') && variable_get('answers_redirect_from_answer_to_question_nodes_p', TRUE)) {
+    if (($node->type == 'answer') && $page) {
+      $question_nid = $node->field_answer_question[0]['nid'];
+      if ($question_nid) {
+        drupal_goto('node/' . $question_nid, NULL, 'node-' . $node->nid);
+      }
+    }
+  }
+}
+ 
\ No newline at end of file
diff --git a/node-answer.tpl.php b/node-answer.tpl.php
new file mode 100644
index 0000000..4b5b156
--- /dev/null
+++ b/node-answer.tpl.php
@@ -0,0 +1,31 @@
+<?php
+?>
+<div id="node-<?php print $node->nid; ?>" class="node<?php if ($sticky) { print ' sticky'; } ?><?php if (!$status) { print ' node-unpublished'; } ?>">
+
+<?php print $picture ?>
+
+<?php if ($page == 0): ?>
+  <h2><?php print $title ?></h2>
+<?php endif; ?>
+
+  <?php if ($submitted): ?>
+    <span class="submitted"><?php print $submitted; ?></span>
+  <?php endif; ?>
+
+  <div class="content clear-block">
+    <?php print $content ?>
+  </div>
+
+  <div class="clear-block">
+    <div class="meta">
+    <?php if ($taxonomy): ?>
+      <div class="terms"><?php print $terms ?></div>
+    <?php endif;?>
+    </div>
+
+    <?php if ($links): ?>
+      <div class="links"><?php print $links; ?></div>
+    <?php endif; ?>
+  </div>
+
+</div>
-- 
1.7.4.msysgit.0

