From 256ee799b64605ae9af3c85fb4eaaea6e48cf49f Mon Sep 17 00:00:00 2001
From: Pavel Karoukin <pavel@karoukin.us>
Date: Fri, 28 Sep 2012 23:03:30 -0400
Subject: [PATCH] Issue #1798548 by pavel.karoukin: If Select or Other module
 installed and enabled, allow user to select custom
 delimiter in CSV Parser settings.

---
 plugins/FeedsCSVParser.inc |   93 +++++++++++++++++++++++++++++++++----------
 1 files changed, 71 insertions(+), 22 deletions(-)

diff --git a/plugins/FeedsCSVParser.inc b/plugins/FeedsCSVParser.inc
index 337dd68..77f626b 100644
--- a/plugins/FeedsCSVParser.inc
+++ b/plugins/FeedsCSVParser.inc
@@ -133,17 +133,41 @@ class FeedsCSVParser extends FeedsParser {
     $items[] = format_plural(count($uniques), t('Column <strong>!column</strong> is mandatory and considered unique: only one item per !column value will be created.', array('!column' => implode(', ', $uniques))), t('Columns <strong>!columns</strong> are mandatory and values in these columns are considered unique: only one entry per value in one of these column will be created.', array('!columns' => implode(', ', $uniques))));
     $items[] = l(t('Download a template'), 'import/' . $this->id . '/template');
     $form['help']['#markup'] = '<div class="help"><p>' . $output . '</p>' . theme('item_list', array('items' => $items)) . '</div>';
-    $form['delimiter'] = array(
-      '#type' => 'select',
-      '#title' => t('Delimiter'),
-      '#description' => t('The character that delimits fields in the CSV file.'),
-      '#options'  => array(
-        ',' => ',',
-        ';' => ';',
-        'TAB' => 'TAB',
-      ),
-      '#default_value' => isset($source_config['delimiter']) ? $source_config['delimiter'] : ',',
-    );
+
+    if (module_exists("select_or_other")) {
+      $form['delimiter'] = array(
+        '#type' => 'select_or_other',
+        '#title' => t('Delimiter'),
+        '#description' => t('The character that delimits fields in the CSV file.'),
+        '#options'  => array(
+          ',' => ',',
+          ';' => ';',
+          'TAB' => 'TAB',
+        ),
+        '#default_value' => isset($source_config['delimiter']) ? $source_config['delimiter'] : ',',
+        '#other' => t('Other'),
+        '#required' => TRUE,
+        '#multiple' => FALSE,
+        '#select_type' => 'select',
+        '#other_unknown_defaults' => 'other',
+        '#other_delimiter' => "\t",
+        '#other_maxlength' => 1,
+        '#other_size' => 1,
+      );
+    }
+    else {
+      $form['delimiter'] = array(
+        '#type' => 'select',
+        '#title' => t('Delimiter'),
+        '#description' => t('The character that delimits fields in the CSV file.'),
+        '#options'  => array(
+          ',' => ',',
+          ';' => ';',
+          'TAB' => 'TAB',
+        ),
+        '#default_value' => isset($source_config['delimiter']) ? $source_config['delimiter'] : ',',
+      );
+    }
     $form['no_headers'] = array(
       '#type' => 'checkbox',
       '#title' => t('No Headers'),
@@ -168,17 +192,42 @@ class FeedsCSVParser extends FeedsParser {
    */
   public function configForm(&$form_state) {
     $form = array();
-    $form['delimiter'] = array(
-      '#type' => 'select',
-      '#title' => t('Default delimiter'),
-      '#description' => t('Default field delimiter.'),
-      '#options' => array(
-        ',' => ',',
-        ';' => ';',
-        'TAB' => 'TAB',
-      ),
-      '#default_value' => $this->config['delimiter'],
-    );
+
+    if (module_exists("select_or_other")) {
+      $form['delimiter'] = array(
+        '#type' => 'select_or_other',
+        '#title' => t('Default delimiter'),
+        '#description' => t('Default field delimiter.'),
+        '#options' => array(
+          ',' => ',',
+          ';' => ';',
+          'TAB' => 'TAB',
+        ),
+        '#default_value' => $this->config['delimiter'],
+        '#other' => t('Other'),
+        '#required' => TRUE,
+        '#multiple' => FALSE,
+        '#select_type' => 'select',
+        '#other_unknown_defaults' => 'other',
+        '#other_delimiter' => "\t",
+        '#other_maxlength' => 1,
+        '#other_size' => 1,
+      );
+    }
+    else {
+      $form['delimiter'] = array(
+        '#type' => 'select',
+        '#title' => t('Default delimiter'),
+        '#description' => t('Default field delimiter.'),
+        '#options' => array(
+          ',' => ',',
+          ';' => ';',
+          'TAB' => 'TAB',
+        ),
+        '#default_value' => $this->config['delimiter'],
+      );
+    }
+
     $form['no_headers'] = array(
       '#type' => 'checkbox',
       '#title' => t('No headers'),
--
1.7.8.2
