Automatically Make Paths Lowercased
koro - October 1, 2007 - 03:52
| Project: | Custom Breadcrumbs |
| Version: | 5.x-1.2 |
| Component: | User interface |
| Category: | support request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | postponed |
Jump to:
Description
Hi,
I am trying to figure out how to make my custom breadcrumbs' paths to be lowercased. For example, I am using the CCK text tokens of select drop-down fields that contain values such as Apples, Bananas, and Oranges. However, when using the CCK text token for dynamically creating paths, the URL for the breadcrumb shows up something like mysite.com/Apples, when it should be mysite.com/apples to display the page correctly. Perhaps there is some way via PHP to automatically make the path lowercased?
Thanks!

#1
This should be pretty straightforward, but I'm concerned that it might cause problems with other paths. I'd hate to add yet another setting/preference to the module just to toggle lowercasing. I'll think about this one for a bit...
#2
koro,
Have you consider to theme your breadcrumb instead? Put the code snippet below in your template.php file.
<?phpfunction phptemplate_breadcrumb($breadcrumb) {
if (!empty($breadcrumb)) {
return '<div class="breadcrumb">'. strtolower(implode(' » ', $breadcrumb)) .'</div>';
}
}
?>
#3
If anyone else is interested I just had to do the same thing and I just added a strtolower (string to lower) so that function custom_breadcrumbs_nodeapi became
<?php
function custom_breadcrumbs_nodeapi($node, $op, $teaser, $page) {
if ($op == 'view' && !$teaser && $page) {
if ($breadcrumb = _custom_breadcrumbs_load_for_type($node->type)) {
$titles = explode("\n", $breadcrumb->titles);
$paths = explode("\n", $breadcrumb->paths);
$titles = module_exists('token') ? token_replace($titles, 'node', $node) : $titles;
$paths = module_exists('token') ? token_replace($paths, 'node', $node) : $paths;
$trail = array(l(t('Home'), ''));
for ($i = 0; $i < count($titles); $i++) {
// skip empty titles
if ($title = trim($titles[$i])) {
$trail[] = l($title, strtolower(trim($paths[$i])));
}
}
drupal_set_breadcrumb($trail);
}
}
}
?>
Custom breadcrumbs rules by the way. How else would I ever get my crazy directory location view to end up on a single node without anyone being able to tell I went from view to node? This made the complex oh so simple.
#4
I wish this worked for me, but it doesn't seem to (this solution just above, to change the module). Perhaps I'm doing something wrong?
I'm using the zen_basic theme, in case that's relevant.
The solution slightly farther above (to add a function to template.php) works fine to make the breadcrumb appear lowercase, but I can't seem to figure out how to make the link itself lowercase for Category terms that are uppercase.
Do you have any other ideas?
Thanks in advance!
:)
Scott
#5
you can use CSS to change case
#6
avolve – this issue just above was about making categories appear lowercase in the URL (when added using token)... not about the breadcrumb display, which you're right, can be changed with css.
This is a bit of an old issue at this point, and I wonder if it has been solved since? Personally I have had to use a different solution (than using categories in the url) because this didn't work for me.
Any advice is welcome :)
#7
my mistake, sorry. Only skimmed through this looking for guidance on another issue (views breadcrumbs).
#8
Thank you Jody Lynn, your code worked for me(Drupal version: 6.8). I used only
strtolower(trim($paths[$i]))part. Other solutions(CSS and template.php hack) lowercase both link text and URL, but Jody's code lowercases only URL.I want to share how it worked:
In custom_breadcrumbs.module file, in
function custom_breadcrumbs_nodeapi($node, $op, $teaser, $page)function, i changed the code parttrim($paths[$i])asstrtolower(trim($paths[$i]))That's all.
I would not prefer to change any module code; but i tried a lot of things and code hack was the only way. :(
I also want to thank to Eaton for this nice module.
#9
Upss!
It did not work for Turkish paths/terms. Jody's code might still be useful for some issues, but for terms, i realised a better way. No code changes, no another hacks(so i reverted the module file). The solution was there already. My mistake :(.
Solution is to use [termalias] token for path, not [term] or [term-raw]:
Titles: [term]
Paths: [termalias]
PS: Module version: 6.x-1.4