? ._primary_term.module
Index: primary_term.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/primary_term/primary_term.install,v
retrieving revision 1.2
diff -u -8 -p -u -p -r1.2 primary_term.install
--- primary_term.install	15 Sep 2008 14:14:57 -0000	1.2
+++ primary_term.install	10 Nov 2010 09:19:58 -0000
@@ -1,21 +1,40 @@
 <?php
+// $Id$
 
+/**
+ * @file
+ * Installation file for the Primary Term module.
+ */
+
+/**
+ * Implementation of hook_install().
+ */
 function primary_term_install() {
   drupal_install_schema('primary_term');
   // weight module to run after taxonomy
   db_query("UPDATE {system} SET weight = 9 WHERE name = 'primary_term'");
 }
 
+/**
+ * Implementation of hook_uninstall().
+ */
 function primary_term_uninstall() {
   drupal_uninstall_schema('primary_term');
+
+  // TODO: delete all variables set by the module
 }
 
+/**
+ * Implementation of hook_schema().
+ */
 function primary_term_schema() {
+  $schema = array();
+
   $schema['primary_term'] = array(
     'fields' => array(
       'vid' => array(
         'type' => 'int',
         'unsigned' => TRUE,
         'not null' => TRUE,
         'default' => 0,
       ),
@@ -23,10 +42,11 @@ function primary_term_schema() {
         'type' => 'int',
         'unsigned' => TRUE,
         'not null' => TRUE,
         'default' => 0,
       ),
     ),
     'primary key' => array('vid'),
   );
+
   return $schema;
 }
Index: primary_term.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/primary_term/primary_term.module,v
retrieving revision 1.8.2.16
diff -u -8 -p -u -p -r1.8.2.16 primary_term.module
--- primary_term.module	18 Oct 2010 20:45:30 -0000	1.8.2.16
+++ primary_term.module	10 Nov 2010 09:19:59 -0000
@@ -1,70 +1,79 @@
 <?php
-
 // $Id: primary_term.module,v 1.8.2.16 2010/10/18 20:45:30 brianV Exp $
 
 /**
- * @TODO
- * - add a validate function to the form_alter
+ * @file
+ * Allows selection of a primary term for nodes
  */
 
+/**
+ * Implementation of hook_nodeapi().
+ */
 function primary_term_nodeapi(&$node, $op, $teaser, $page) {
   // This module sets $node->primary_term on node load but
   // $node->primaryterm via the node form.  I don't know if a previous
   // author meant that or if it was a mistake.  For now, the module
   // preserves that behavior.
 
-  switch ($op){
+  switch ($op) {
     case 'presave':
       // Make sure the PT is assigned to the node as a normal term.
       //
       // taxonomy_node_save() allows $node->taxonomy to contain tids,
       // term objects, or arrays of tids (keyed by vocabulary).  So,
       // we can add the PT tid to the end of the array.
       //
       // However, taxonomy_node_save() assumes that a given tid only
       // occurs once anywhere in node->taxonomy(), so we have to make
       // sure the PT tid is not already assigned via the form to this
       // node before adding it.
       //
       // In the end, this is more work than doing it "wrong" during
       // insert/update.
       if (!empty($node->primaryterm)) {
         $tid = $node->primaryterm;
-      } else if (!empty($node->primary_term)) {
+      }
+      elseif (!empty($node->primary_term)) {
         $tid = $node->primary_term->tid;
       }
+
       if (!empty($tid)) {
         foreach ($node->taxonomy as $k => $v) {
           if (is_object($v) && $v->tid == $tid) {
             return;
-          } else if (is_array($v) && !empty($v[$tid])) {
+          }
+          elseif (is_array($v) && !empty($v[$tid])) {
             return;
-          } else if (is_numeric($v) && $v == $tid) {
+          }
+          elseif (is_numeric($v) && $v == $tid) {
             return;
           }
         }
+
         $node->taxonomy[] = $tid;
+
         // Load the term so it's available to token/pathauto
         $node->primary_term = taxonomy_get_term($tid);
       }
       break;
 
     case 'insert':
     case 'update':
       db_query('DELETE FROM {primary_term} WHERE vid = %d', $node->vid); // only one term per node revision
       // When node form is submitted, the new PT tid comes in as
       // $node->primaryterm (because it is set as
       // $form['taxonomy']['primaryterm'] but with #tree => false.  If
       // it is comes directly from node_load(), the PT term object is
       // in $node->primary_term.
       if (!empty($node->primaryterm)) {
         $primaryterm = $node->primaryterm;
-      } else if (!empty($node->primary_term)) {
+      }
+      elseif (!empty($node->primary_term)) {
         $primaryterm = $node->primary_term->tid;
       }
       if (empty($primaryterm)) {
         break;
       }
 
       db_query('INSERT INTO {primary_term} (vid, tid) VALUES (%d, %d)', $node->vid, $primaryterm);
       break;
@@ -191,20 +200,18 @@ function primary_term_node_type_form_val
     form_set_error('pt_required','If you choose to make the Primary Term required, you must select at least one vocabulary for it.');
   }
 }
 
 /**
  * Get primary term for a given node version id (vid)
  *
  * @param integer $vid
- *//**
-* Implementation of CCK's hook_content_extra_fields.
-*/
-function primary_term_get_term($vid){
+ */
+function primary_term_get_term($vid) {
   return db_result(db_query('SELECT tid FROM {primary_term} WHERE vid = %d', $vid));
 }
 
 /**
  * Check permission to access the vocabulary with the given vid.
  *
  * Currently used to add support for taxonomy_role.
  *
@@ -220,51 +227,61 @@ function primary_term_vocabulary_access(
 
   $vocabularies = taxonomy_get_vocabularies();
   if (is_numeric($vid) && user_access('access '. check_plain($vocabularies[$vid]->name) .' vocabulary')) {
     return TRUE;
   }
   else {
     return FALSE;
   }
-
 }
 
 /**
-* Implementation of CCK's hook_content_extra_fields.
-*/
+ * Implementation of hook_content_extra_fields().
+ */
 function primary_term_content_extra_fields() {
+  $extras = array();
+
   $extras['primary_term'] = array(
     'label' => t('Primary Term'),
-    'description' => t('Primary Term widget (node editing only)'),
+    'description' => t('Primary term widget (node editing only)'),
     'weight' => 0,
   );
+
   return $extras;
 }
 
-/**********************************************************************
- * token.module support
- **********************************************************************/
+/**
+ * Token support
+ */
 
+/**
+ * Implementation of hook_token_list().
+ */
 function primary_term_token_list($type = 'all') {
   if ($type == 'node' || $type == 'all') {
     $tokens['node']['primary-term'] = t('Name of primary term');
     $tokens['node']['primary-term-id'] = t('ID of primary term');
     $tokens['node']['primary-termpath-raw'] = t('Full Path to Primary Term');
     $tokens['node']['primary-term-vocab'] = t('Name of the vocab of primary term');
 
   if (module_exists('uc_catalog')) {
     $tokens['node']['primary-termpath-uc-raw'] = t('Full catalog path to Primary Term');
   }
 
     return $tokens;
   }
 }
 
+/**
+ * Implementation of hook_token_values().
+ */
 function primary_term_token_values($type, $object = NULL) {
+  $values = array();
+
   switch ($type) {
     case 'node':
       $node = $object;
       if (isset($node->primaryterm)) {
         $term = taxonomy_get_term($node->primaryterm);
         $values['primary-term'] = check_plain($term->name);
         $values['primary-term-id'] = $term->tid;
         $values['primary-termpath-raw'] = drupal_get_path_alias(taxonomy_term_path($term));
@@ -276,71 +293,79 @@ function primary_term_token_values($type
           $values['primary-termpath-uc-raw'] = drupal_get_path_alias(uc_catalog_path($term));
         }
       }
       break;
   }
   return $values;
 }
 
-/**********************************************************************
+/**
  * Views support
- **********************************************************************/
+ */
 
 /**
  * Implementation of hook_views_api().
  */
 function primary_term_views_api() {
   return array(
     'api' => 2,
     'path' => drupal_get_path('module', 'primary_term') . '/includes/views',
-
   );
 }
 
-/**********************************************************************
+/**
  * CTools support
- **********************************************************************/
+ */
 
 /**
  * Implementation of hook_ctools_plugin_directory().
  *
  * It simply tells panels where to find the .inc files that define various
  * args, contexts, content_types. In this case the subdirectories of
  * mypane/panels are used.
  */
 function primary_term_ctools_plugin_directory($module, $plugin) {
   if ($module == 'ctools' && !empty($plugin)) {
     return "plugins/$plugin";
   }
 }
 
-/**********************************************************************
+/**
  * Context support
- **********************************************************************/
+ */
 
+/**
+ * Implementation of hook_ctools_plugin_api().
+ */
 function primary_term_ctools_plugin_api($module, $api) {
   if ($module == 'context' && $api == 'plugins') {
     return array('version' => 3);
   }
 }
 
+/**
+ * Implementation of hook_context_plugins().
+ */
 function primary_term_context_plugins() {
   $plugins = array();
   $plugins['primary_term_context_condition_primary_term'] = array(
     'handler' => array(
       'path' => drupal_get_path('module', 'primary_term') . '/plugins/context',
       'file' => 'primary_term_context_condition_primary_term.inc',
       'class' => 'primary_term_context_condition_primary_term',
       'parent' => 'context_condition_node',
     ),
   );
   return $plugins;
 }
 
+/**
+ * Implementation of hook_context_registry().
+ */
 function primary_term_context_registry() {
   return array(
     'conditions' => array(
       'primary_term' => array(
         'title' => t('Primary Term'),
         'plugin' => 'primary_term_context_condition_primary_term',
       ),
     ),
Index: plugins/context/primary_term_context_condition_primary_term.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/primary_term/plugins/context/Attic/primary_term_context_condition_primary_term.inc,v
retrieving revision 1.1.2.1
diff -u -8 -p -u -p -r1.1.2.1 primary_term_context_condition_primary_term.inc
--- plugins/context/primary_term_context_condition_primary_term.inc	13 Oct 2010 17:56:04 -0000	1.1.2.1
+++ plugins/context/primary_term_context_condition_primary_term.inc	10 Nov 2010 09:19:59 -0000
@@ -1,11 +1,16 @@
 <?php
 // $Id: primary_term_context_condition_primary_term.inc,v 1.1.2.1 2010/10/13 17:56:04 brianV Exp $
 
+/**
+ * @file
+ * Primary term plugin for Context.
+ */
+
 class primary_term_context_condition_primary_term extends context_condition_node {
   function condition_values() {
     $values = array();
     if (module_exists('taxonomy')) {
       foreach (taxonomy_get_vocabularies() as $vocab) {
         if (empty($vocab->tags)) {
           foreach (taxonomy_get_tree($vocab->vid) as $term) {
             $values[$term->tid] = $term->name;
@@ -29,9 +34,8 @@ class primary_term_context_condition_pri
     $map = context_condition_map();
     if (!empty($map['primary_term']) && $node->primary_term->tid) {
       foreach ($this->get_contexts($node->primary_term->tid) as $context) {
         $this->condition_met($context, $node->primary_term->tid);
       }
     }
   }
 }
-?>
