From 443015210f223fcb32463d01f4b40840e5143838 Mon Sep 17 00:00:00 2001
From: Michael Strelan <mstrelan@gmail.com>
Date: Tue, 7 Jun 2011 14:44:30 +1000
Subject: [PATCH] Views field link case transform path

---
 handlers/views_handler_field.inc |   42 ++++++++++++++++++++++++++++++++++++++
 1 files changed, 42 insertions(+), 0 deletions(-)

diff --git a/handlers/views_handler_field.inc b/handlers/views_handler_field.inc
index bf00f93..ee5c4d5 100644
--- a/handlers/views_handler_field.inc
+++ b/handlers/views_handler_field.inc
@@ -354,6 +354,7 @@ class views_handler_field extends views_handler {
         'absolute' => array('default' => '', 'translatable' => FALSE),
         'external' => array('default' => '', 'translatable' => FALSE),
         'replace_spaces' => array('default' => '', 'translatable' => FALSE),
+        'path_case' => array('default' => 'none', 'translatable' => FALSE),
         'trim_whitespace' => array('default' => FALSE),
         'alt' => array('default' => '', 'translatable' => TRUE),
         'rel' => array('default' => ''),
@@ -652,6 +653,22 @@ class views_handler_field extends views_handler {
           'edit-options-alter-make-link' => array(1)
         ),
       );
+      $form['alter']['path_case'] = array(
+        '#type' => 'select',
+        '#title' => t('Case in path'),
+        '#description' => t('When printing url paths, how to transform the case of the filter value.'),
+        '#options' => array(
+          'none' => t('No transform'),
+          'upper' => t('Upper case'),
+          'lower' => t('Lower case'),
+          'ucfirst' => t('Capitalize first letter'),
+          'ucwords' => t('Capitalize each word'),
+        ),
+        '#default_value' => $this->options['alter']['path_case'],
+        '#dependency' => array(
+          'edit-options-alter-make-link' => array(1)
+        ),
+      );      
       $form['alter']['external'] = array(
         '#type' => 'checkbox',
         '#title' => t('External server URL'),
@@ -1065,6 +1082,10 @@ If you would like to have the characters %5B and %5D please use the html entity
       // were removed by check_plain().
       $path = strip_tags(html_entity_decode(strtr($path, $tokens)));
 
+      if ($alter['path_case'] != 'none') {
+        $path = $this->case_transform($path, 'path_case');
+      }      
+      
       if (!empty($alter['replace_spaces'])) {
         $path = str_replace(' ', '-', $path);
       }
@@ -1177,6 +1198,27 @@ If you would like to have the characters %5B and %5D please use the html entity
     return $value;
   }
 
+  function case_transform($string, $option) {
+    global $multibyte;
+
+    switch ($this->options['alter'][$option]) {
+      default:
+        return $string;
+      case 'upper':
+        return drupal_strtoupper($string);
+      case 'lower':
+        return drupal_strtolower($string);
+      case 'ucfirst':
+        return drupal_strtoupper(drupal_substr($string, 0, 1)) . drupal_substr($string, 1);
+      case 'ucwords':
+        if ($multibyte == UNICODE_MULTIBYTE) {
+          return mb_convert_case($string, MB_CASE_TITLE);
+        } else {
+          return ucwords($string);
+        }
+    }
+  }    
+  
   /**
    * Get the 'render' tokens to use for advanced rendering.
    *
-- 
1.7.4

