diff --git a/handlers/views_handler_field.inc b/handlers/views_handler_field.inc index bf00f93..8f31c5f 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), + 'case' => array('default' => 'none', 'translatable' => FALSE), 'trim_whitespace' => array('default' => FALSE), 'alt' => array('default' => '', 'translatable' => TRUE), 'rel' => array('default' => ''), @@ -661,7 +662,22 @@ class views_handler_field extends views_handler { 'edit-options-alter-make-link' => array(1), ), ); - + $form['alter']['case'] = array( + '#type' => 'select', + '#title' => t('Transform the case'), + '#description' => t('When printing url paths, how to transform the case of the filter value. Do not use this unless with Postgres as it uses case sensitive comparisons.'), + '#dependency' => array( + 'edit-options-alter-make-link' => array(1), + ), + '#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']['case'], + ); $form['alter']['link_class'] = array( '#title' => t('Link class'), '#type' => 'textfield', @@ -1037,7 +1053,30 @@ If you would like to have the characters %5B and %5D please use the html entity } return views_trim_text($alter, $value); } - + /** + * Transform the case of a string biased on the option provided. + */ + function case_transform($string, $option) { + global $multibyte; + + switch ($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); + } + } + } + /** * Render this field as a link, with the info from a fieldset set by * the user. @@ -1068,6 +1107,10 @@ If you would like to have the characters %5B and %5D please use the html entity if (!empty($alter['replace_spaces'])) { $path = str_replace(' ', '-', $path); } + + if (!empty($alter['case']) && $alter['case'] != 'none') { + $path = $this->case_transform($path, $alter['case']); + } } // Parse the URL and move any query and fragment parameters out of the path.