Index: barcode.module
===================================================================
--- barcode.module	(revision 4195)
+++ barcode.module	(working copy)
@@ -77,7 +77,7 @@
   if (empty($variables['barcode_value'])) {
     return '';
   }
-  
+
   $barcode = barcode_get_settings();
 
   if (isset($variables['encoding'])) {
@@ -150,26 +150,61 @@
 }
 
 /**
+ * Implementation of hook_barcode_type
+ */
+function barcode_barcode_type() {
+  $plugins['ean'] = array(
+      'UPC-A' => t('UPC-A'),
+      'EAN-13' => t('EAN-13'),
+      'ISBN' => t('ISBN')
+  );
+  $plugins['ean8'] = array('EAN-8' => t('EAN-8'));
+  $plugins['upce'] = array('UPC-E' => t('UPC-E'));
+  $plugins['s2o5'] = array(
+      'S2O5' => t('Standard 2 of 5'),
+      'I2O5' => t('Industrial 2 of 5')
+  );
+  $plugins['i25'] = array('I25' => t('Interleaved 2 of 5'));
+  $plugins['postnet'] = array('POSTNET' => t('Postnet'));
+  $plugins['codabar'] = array('CODABAR' => t('Codabar'));
+  $plugins['code128'] = array('CODE128' => t('Code 128'));
+  $plugins['code39'] = array('CODE39' => t('Code 39'));
+  $plugins['code93'] = array('CODE93' => t('Code 93'));
+  $plugins['qrcode'] = array('QRCODE' => t('QR Code'));
+
+  return array('barcode' => $plugins);
+}
+
+/**
+* Builds and return a list of all plugins available in the system.
+*
+* @return Nested array of plugins, grouped by type and
+*/
+function barcode_discover_plugins() {
+  static $modules_plugin;
+  if(!isset($modules_plugin)) {
+    // Get plugins from barcode and other modules
+    $modules_plugin = module_invoke_all('barcode_type');
+  }
+  return $modules_plugin;
+}
+
+/**
  * Implements hook_field_settings_form().
  */
 function barcode_field_settings_form($field, $instance, $has_data) {
   $form = array();
-  $option = array(
-    'UPC-A' => t('UPC-A'),
-    'EAN-13' => t('EAN-13'),
-    'ISBN' => t('ISBN'),
-    'UPC-E' => t('UPC-E'),
-    'EAN-8' => t('EAN-8'),
-    'S2O5' => t('Standard 2 of 5'),
-    'I2O5' => t('Industrial 2 of 5'),
-    'I25' => t('Interleaved 2 of 5'),
-    'POSTNET' => t('Postnet'),
-    'CODABAR' => t('Codabar'),
-    'CODE128' => t('Code 128'),
-    'CODE39' => t('Code 39'),
-    'CODE93' => t('Code 93'),
-    'QRCODE' => t('QR Code')
-  );
+
+  // Get plugins from barcode and other modules
+  $modules_plugin = barcode_discover_plugins();
+  foreach($modules_plugin as $module => $plugins) {
+    foreach ($plugins as $plugin => $encodings) {
+      foreach ($encodings as $encoding => $display_string) {
+        $option[$encoding] = $display_string;
+      }
+    }
+  }
+
   $form['encoding'] = array(
       '#type' => 'select',
       '#title' => t('Code Type'),
@@ -239,7 +274,7 @@
     '#maxlength' => 4,
     '#required' => TRUE,
   );
-  
+
   // Add token module replacements fields
   if (module_exists('token')) {
     $form['tokens'] = array(
@@ -261,7 +296,7 @@
       '#markup' => theme('token_tree', $token_type),
     );
   }
-  
+
   return $form;
 }
 
@@ -286,12 +321,12 @@
 /***********************************************************************
  *  Field Type API: Formatter
  **********************************************************************/
- 
+
 /**
  * Implements hook_field_formatter_info().
  */
 function barcode_field_formatter_info() {
-  return array( 
+  return array(
     'barcode_default' => array(
       'label' => t('Barcode Image'),
       'field types' => array('barcode_field'),
@@ -302,7 +337,7 @@
     ),
   );
 }
- 
+
 /**
  * Implements hook_field_formatter_view().
  */
@@ -319,10 +354,10 @@
       $temp = array('barcode_value' => check_plain($items[$delta]['value']),'encoding' => $field['settings']['encoding'], 'height' => $instance['settings']['barcode_height'], 'image_format' => $instance['settings']['barcode_image_format']);
       if ($field['settings']['encoding'] != 'QRCODE') {
         $temp += array('bgcolor' => $instance['settings']['barcode_bgcolor'], 'barcolor' => $instance['settings']['barcode_barcolor'], 'scale' => $instance['settings']['barcode_scale']);
-      } 
+      }
       $element[$delta] = array('#markup' => theme('barcode_image', $temp));
     }
-  }  
+  }
 
   return $element;
 }
@@ -379,7 +414,7 @@
         '#size' => 20,
       );
     break;
-    
+
     case 'barcode_textarea':
       $element['value'] += array(
         '#type' => 'textarea',
Index: includes/barcode.plugins.inc
===================================================================
--- includes/barcode.plugins.inc	(revision 4195)
+++ includes/barcode.plugins.inc	(working copy)
@@ -2,51 +2,28 @@
 
 /**
  * @file
- * Code to load barcode symbology plugins 
- */ 
-
-/**
- * Builds and return a list of all plugins available in the system.
- *
- * @return Nested array of plugins, grouped by type and
+ * Code to load barcode symbology plugins
  */
-function barcode_discover_plugins() {
-  // @TODO: we should probably just turn the plugins into modules and discover
-  // this through hooks.
-  $plugins['ean'] = array(
-    'UPC-A' => t('UPC-A'),
-    'EAN-13' => t('EAN-13'),
-    'ISBN' => t('ISBN')
-  );
-  $plugins['ean8'] = array('EAN-8' => t('EAN-8'));
-  $plugins['upce'] = array('UPC-E' => t('UPC-E'));
-  $plugins['s2o5'] = array(
-    'S2O5' => t('Standard 2 of 5'), 
-    'I2O5' => t('Industrial 2 of 5')
-  );
-  $plugins['i25'] = array('I25' => t('Interleaved 2 of 5'));
-  $plugins['postnet'] = array('POSTNET' => t('Postnet'));
-  $plugins['codabar'] = array('CODABAR' => t('Codabar'));
-  $plugins['code128'] = array('CODE128' => t('Code 128'));
-  $plugins['code39'] = array('CODE39' => t('Code 39'));
-  $plugins['code93'] = array('CODE93' => t('Code 93'));
-  $plugins['qrcode'] = array('QRCODE' => t('QR Code'));
-  return $plugins;
-}
+
+
 
 /**
  * Return the plugin filename containing the given encoding.
  */
 function barcode_load_plugin($encoding_name) {
-  $plugins = barcode_discover_plugins();
-  foreach ($plugins as $plugin => $encodings) {
-    foreach ($encodings as $encoding => $display_string) {
-      if ($encoding == $encoding_name) {
-        module_load_include('inc', 'barcode', 'plugins/' . $plugin);
-        return $plugin;
+  $modules_plugin = barcode_discover_plugins();
+
+  foreach($modules_plugin as $module => $plugins) {
+    foreach ($plugins as $plugin => $encodings) {
+      foreach ($encodings as $encoding => $display_string) {
+        if ($encoding == $encoding_name) {
+          module_load_include('inc', $module, 'plugins/' . $plugin);
+          return $plugin;
+        }
       }
     }
   }
+
   return '';
 }
 
@@ -71,7 +48,7 @@
   $name = md5($variables['barcode_value']);
   $filename_noformat = $barcode['default_path'] .'/'. $name . $variables['encoding'];
   $filename = $filename_noformat .'.'. $variables['image_format'];
-  
+
   // First check if the images already exists.
   if (!file_exists($filename)) {
     $plugin = barcode_load_plugin($variables['encoding']);
@@ -88,11 +65,11 @@
     if ($variables['encoding'] != 'QRCODE') {
       $settings->color = array(hexdec(substr($variables['barcolor'], 1, 2)), hexdec(substr($variables['barcolor'], 3, 2)), hexdec(substr($variables['barcolor'], 5, 2)));
       $settings->bgcolor = array(hexdec(substr($variables['bgcolor'], 1, 2)), hexdec(substr($variables['bgcolor'], 3, 2)), hexdec(substr($variables['bgcolor'], 5, 2)));
-      $settings->scale = $variables['scale'];   
+      $settings->scale = $variables['scale'];
     }
     barcode_plugin_generate_image($plugin, $variables['barcode_value'], $settings);
   }
-  
+
   if (!file_exists($filename)) {
     watchdog('barcode', 'Failed to generate image using settings @settings', array('@settings' => print_r($settings, TRUE)));
     return FALSE;
@@ -104,7 +81,7 @@
 function barcode_check_digit($barnumber, $number) {
   $csum_total = 0; // The checksum working variable starts at zero
 
-  // If the source message string is less than 12 characters long, we make it 
+  // If the source message string is less than 12 characters long, we make it
   // 12 characters
   if (strlen($barnumber) < $number) {
     $barnumber = str_pad($barnumber, $number, "0", STR_PAD_LEFT);
